Get the Value from a CRM Field
var varMyValue = Xrm.Page.getAttribute("CRMFieldSchemaName").getValue() ;
Set the Value of a CRM Field
Xrm.Page.getAttribute("CRMFieldSchemaName").setValue('My New Value');
Hide/Show Tab
Xrm.Page.ui.tabs.get(5).setVisible(false);
Xrm.Page.ui.tabs.get(5).setVisible(true);
Hide/Show Section
Xrm.Page.ui.tabs.get(5).sections.get(0).setVisible(false);
Xrm.Page.ui.tabs.get(5).sections.get(0).setVisible(true);
Call the On-Change Event of a Field
Xrm.Page.getAttribute("CRMFieldSchemaName").fireOnChange();
Get the Selected Value of a Pick-List
Xrm.Page.getAttribute("CRMFieldSchemaName").getSelectedOption().text;
Set Field Requirement Level
Xrm.Page.getAttribute("CRMFieldSchemaName").setRequiredLevel("none");
Xrm.Page.getAttribute("CRMFieldSchemaName").setRequiredLevel("required");
Xrm.Page.getAttribute("CRMFieldSchemaName").setRequiredLevel("recommended");
Set the Focus to a Field
Xrm.Page.getControl("CRMFieldSchemaName").setFocus(true);
Stop an On-Save Event
event.returnValue = false;
executionObj.getEventArgs().preventDefault();
Return Array of Strings Consisting of User Security Role GUIDs
Xrm.Page.context.getUserRoles();
Get Record GUID
var recordId = Xrm.Page.data.entity.getId();
var recordIdWithoutCurlyBraces = Xrm.Page.data.entity.getId().substring(1,37);
Get Event Source
var eventSource = executionContext.getEventSource();
Get Event Source (Field Name)
var fieldName = executionContext.getEventSource().getName();
Get Event Source (Value)
var fieldValue= executionContext.getEventSource().getValue();
Set Lookup Value
Xrm.Page.getAttribute('new_fieldid').setValue([{ id: 'guid', name: fullName, entityType: 'entityTypeName'}]);
Disable/Enable Field
Xrm.Page.getControl(fieldName).setDisabled(true);
Xrm.Page.getControl(fieldName).setDisabled(false);
Hide/Show Field
Xrm.Page.ui.controls.get(fieldName).setVisible(false);
Xrm.Page.ui.controls.get(fieldName).setVisible(true);
Get Form Type
var FORM_TYPE_CREATE = 1;
var FORM_TYPE_UPDATE = 2;
var FORM_TYPE_READ_ONLY = 3;
var FORM_TYPE_DISABLED = 4;
var FORM_TYPE_QUICK_CREATE = 5;
var FORM_TYPE_BULK_EDIT = 6;
var formType = Xrm.Page.ui.getFormType();
if (formType == FORM_TYPE_CREATE) {
}
else {
}
Modify Field Label Tooltip
document.getElementById("field_name_c").setAttribute("title", "tooltip text");
Modify Lookup Button Tooltip
document.getElementById("field_name").setAttribute("title", "tooltip text");
Call a field's On-Change Event
Xrm.Page.getAttribute("field_name").fireOnChange();