CRM Crate

In this course, we will learn to hide / show fields in dynamics 365 CRM using JavaScript. Before we start make sure to go through the below links.

How to hide a field using JavaScript?

We can hide a field with help of “SetVisible” property. For example, if the field “Account Name” is blank, then the field “Account Address” will be hidden using the below JavaScript code.

function HideField (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 hiding field Account Address.
        formContext.getControl("accountaddress").setVisible(false);
    }
}

As shown in the above snippet, we have used the propertly “setVisible” and set it to false in order to hide the related field “Account Address”.

How to show a field using JavaScript?

We can shown a field with help of “SetVisible” property. For example, if the field “Account Name” is having data, then the field “Account Address” will be shown using the below JavaScript code.

function showField (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 hiding field Account Address.
        formContext.getControl("accountaddress").setVisible(true);
    }
}

As shown in the above snippet, we have used the property “setVisible” and set it to true in order to show the related field “Account Address”.


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.