CRM Crate

In this course, we will learn to lock and unlock the fields using JavaScript in Microsoft Dynamics CRM. Before we start make sure to go through the below links.

In Microsoft Dynamics 365, we can dynamically lock (enable) and unlock (disable) fields with help of JavaScript.

JavaScript snippet for locking a field

We will use the property called “setDisable” to lock a particular field dynamically as shown below. In the below example, we will lock the field “Account Address” when field “Account Name” is empty.

function LockUnlock(executionContext) {

    //Initiated Form Context.
    var formContext = executionContext.getFormContext();

    //Getting Value From Field Account Name.
    var AccountName = formContext.getAttribute("accountname").getValue();

    //Condition If Account Name Is Null.
    if (AccountName === null || AccountName === undefined) {

        //Using SetVisible propertly for locking field Account Address.
        formContext.getControl("accountaddress").setDisabled(true);
    }

JavaScript snippet for unlocking a field

We will use the property called “setDisable” to unlock a particular field dynamically as shown below. In the below example, we will unlock the field “Account Address” when field “Account Name” is having valid data.

function LockUnlock(executionContext) {

    //Initiated Form Context.
    var formContext = executionContext.getFormContext();

    //Getting Value From Field Account Name.
    var AccountName = formContext.getAttribute("accountname").getValue();

    //Condition If Account Name Is Null.
    if (AccountName !== null || AccountName !== undefined) {

        //Using SetVisible propertly for unlocking field Account Address.
        formContext.getControl("accountaddress").setDisabled(false);
    }
}

Thus, we learned how to lock and unlock fields using JavaScript in Microsoft Dynamics 365 CRM.

CRM Crate

All In One Platform For Learning Microsoft CRM.

Facebook
Twitter
LinkedIn
error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.