Thursday, August 2, 2012

CRM 2011 JS


// change CRM fields color to red
crmForm.all.name_c.style.color = "#FF0000";
// Get picklist value
Xrm.Page.getAttribute("<field Schema name>").getValue();

// Get picklist selected text
Xrm.Page.getAttribute("<field Schema name>").getSelectedOption().text;

// Set picklist value
Xrm.Page.getAttribute("<field Schema name>").setValue("<set Int value>");
// Set picklist value to blank
Xrm.Page.getAttribute("<field Schema name>").setValue(null);
// Disable CRM field
Xrm.Page.getControl('<field Schema name>').setDisabled(true);
// set CRM field as required
Xrm.Page.getAttribute("<field Schema name>").setRequiredLevel("required");
// remove required level of the CRM form filed
Xrm.Page.getAttribute("<field Schema name>").setRequiredLevel("none");
// Hide CRM form Field
crmForm.all.<field Schema name>_c.style.display = 'none';
crmForm.all.<field Schema name>_d.style.display = 'none';

// force submit a field on save of the form
Xrm.Page.getAttribute("<Field Schema Name>").setSubmitMode("always");

// Set lookup value to a field
function SetLookupValue(fieldName, id, name, entityType) {
    if (fieldName != null) {
        var lookupValue = new Array();
        lookupValue[0] = new Object();
        lookupValue[0].id = id;
        lookupValue[0].name = name;
        lookupValue[0].entityType = entityType;

        Xrm.Page.getAttribute(fieldName).setValue(lookupValue);
    }
}

No comments: