Thursday, 11 June 2020

Set the CRM Form as Read Only(Disabled) in MS CRM 2011/2013/2015

Sometimes we get requirement to disable each and every field on the CRM form based on a condition.


We can achieve that functionality by writing simple JavaScript.

function setFormAsReadOnly() {
    //Write you conditions here.
    disableFormFields(true);
}

function doesControlHaveAttribute(control) {
    var controlType = control.getControlType();
    return controlType != "iframe" && controlType != "webresource" && controlType != "subgrid";
}

function disableFormFields(onOff) {
    Xrm.Page.ui.controls.forEach(function (control, index) {
        if (doesControlHaveAttribute(control)) {
            control.setDisabled(onOff);
        }
    });
}
Hope this helps.

No comments:

Post a Comment

Dynamics 365 — Retrieve More than 5000 records with FetchXML

  When you’re working with Dynamics 365, you may have encountered a limitation when it comes to retrieving records. The maximum number of re...