Note – Below JavaScript API calls are deprecated in Dynamics 365 V9 due to JavaScript object model changes

#To check the Client: 
var client = Xrm.Page.context.client.getClient();

if (client == “Mobile”) {
// write code for Mobiles / Tablets device
}
if (client == “Web”)  {
// Write code for Web browser / desktop
}
——————————————————————————————————————
#Get value of fields:
*To get value of fields like Text/Decimal/Float/Currency/Whole No:
Xrm.Page.getAttribute(“FieldName”).getValue();

*To get value of Look Up Field:
For ID:  Xrm.Page.getAttribute(“FieldName”).getValue()[0].id;
For Name:  Xrm.Page.getAttribute(“FieldName”).getValue()[0].name;
For EntityType: Xrm.Page.getAttribute(“FieldName”).getValue()[0].entityType;

*To get value of field like Option set/Boolean:
 For Text: Xrm.Page.getAttribute(“FieldName”).getText();
 For Value: Xrm.Page.getAttribute(“FieldName”).getValue();

*To get value of Multiple option set (available in D365 v9.0 ) :
For Value: Xrm.Page.getAttribute(“FieldName”).getValue()[indexValue];
For Text: Xrm.Page.getAttribute(“FieldName”).getText()[indexValue];
// indexValue can be 0,1,2……
——————————————————————————————————————
#Set value of fields:
*To set value of fields like Text/Decimal/Float/Currency/Whole No:
Xrm.Page.getAttribute(“FieldName”).setValue(“value”);

*To set value of Boolean field type:
  Xrm.Page.getAttribute(“FieldName”).setValue(true/false);

*To set value of Option set field type:
  Xrm.Page.getAttribute(“FieldName”).setValue(100000000);

*To set LookUp field type:
var lookUp = new Array();
lookUp[0] = new Object();
lookUp[0].id = recordId;
lookUp[0].name = recordName;   // this is optional
lookUp[0].entityType = entityName;
Xrm.Page.getAttribute(“FieldName”).setValue(lookUp);

*To set value of Multiple option set value:   Xrm.Page.getAttribute(“FieldName”).setValue([100000000,100000001]);
——————————————————————————————————————–
#Check field is mandatory or not:
  var value = Xrm.Page.getAttribute(“FieldName”).getRequiredLevel();
value would be required or none. if required, it means field is mandatory. if none, it means field is not mandatory.

#Make a field mandatory / remove mandatory:

Xrm.Page.getAttribute(“FieldName”).setRequiredLevel(“required”);
Xrm.Page.getAttribute(“FieldName”).setRequiredLevel(“none”);
——————————————————————————————————————–

#Check Visibility of a field:
var value = Xrm.Page.getControl(“FieldName”).getVisible();
value would be true or false. if true, it mean field is visible. if false, it mean field is not visible.

#Show/Hide field:

Xrm.Page.getControl(“FieldName”).setVisible(true/false);
——————————————————————————————————————–
#Check Visibility of a Section:
var value = Xrm.Page.ui.tabs.get(“Tab_Name”).sections.get(“Section”).getVisible();
value would be true or false. if true, it mean section is visible. if false, it mean section is not visible.

#Show/Hide Section:
Xrm.Page.ui.tabs.get(“Tab_Name”).sections.get(“Section”).setVisible(true/false);

——————————————————————————————————————–

#Check Visibility of a Tab:
var value = Xrm.Page.ui.tabs.get(“Tab_Name”).getVisible();
value would be true or false. if true, it mean tab is visible. if false, it mean tab is not visible.

#Show/Hide Tab:
Xrm.Page.ui.tabs.get(“Tab_Name”).setVisible(true/false);

——————————————————————————————————————–
#Check Field is Enable/Disable (read only):
var value = Xrm.Page.getControl(“FieldName”).getDisabled();
value would be true or false. if true, it mean field is disabled. if false, it mean field is not disabled.

#Enable/Disable field (read only):

Xrm.Page.getControl(“FieldName”).setDisabled(false/true);

——————————————————————————————————————–

#Disable/Enable Section (read only):
function disableSection(sectionName){
var controls =Xrm.Page.ui.tabs.get(tabName).sections.get(sectionName).controls.get();
var numberOfControls = controls.length;  
for (var i = 0; i < numberOfControls; i++) {
        controls[i].setDisabled(true/false);
}
}
——————————————————————————————————————–
#Enable/Disable Tab (read only):
var Tab =  Xrm.Page.ui.tabs.get(tabName);
var Sections =  Tab.sections.get();
for (var i in Sections) {
var sectionName = Sections[i].getName();
      disableSection(sectionName);    //  use above function to disable section
}
——————————————————————————————————————–
#Enable/Disable Form (read only):
Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
var control = Xrm.Page.getControl(attribute.getName());
if (control) {
control.setDisabled(true)
}
});
——————————————————————————————————————–
#To save the form:
   Xrm.Page.data.entity.save();
——————————————————————————————————————–
#To get the Entity name:
   var value = Xrm.Page.data.entity.getEntityName();
——————————————————————————————————————–
#To get GUID of a current record:
    var value = Xrm.Page.data.entity.getId();
——————————————————————————————————————–
#Open another entity form:
    Xrm.Utility.openEntityForm( “entityName” );
——————————————————————————————————————–
#Business Process Flow(BPF) Java-Scripts:

#Get BPF’s / Process’s  ID:

   var value = Xrm.Page.data.process.getActiveProcess().getId();

#Get BPF’s / Process’s  Name:

   var value = Xrm.Page.data.process.getActiveProcess().getName();

#Get Visibility of a process:

   var value = Xrm.Page.ui.process.getVisible();

#Set Visibility of a process:

   var value = Xrm.Page.ui.process.setVisible(false/true);

#Get Display State of a process:

   var value = Xrm.Page.ui.process.getDisplayState();
          it can either be collapsed or expanded. 

#Set Display State of a process:

   var value = “collapsed”  or “expanded”
     Xrm.Page.ui.process.setDisplayState(value);

#Get Active Stage Name of a process:

   var value = Xrm.Page.data.process.getActiveStage().getName()

#Get Active Stage ID of a process:
   var value = Xrm.Page.data.process.getActiveStage().getId()

#Call a function when BPF’s stages change or call a function when we click on Next Stage:

   Xrm.Page.data.process.addOnStageChange(function name);

References: Link