Make the field required using JavaScript in D365 CE

In this blog, we will learn how to make a column(field) required using JavaScript in D365 CE(CRM).

Syntax:

formContext.getAttribute(columnName).setRequiredLevel(requirementLevel)

PARAMETER:

Code:

var formCustomizations = {
    setFieldRequired: function (executionContext) {
        let formContext = executionContext.getFormContext();
          
        //this will make the field required
        formContext.getAttribute("avt_date").setRequiredLevel("required");

        //this will make the field recommended
        formContext.getAttribute("avt_customer").setRequiredLevel("recommended");

        //this will make the field not required
        formContext.getAttribute("avt_title").setRequiredLevel("none");
    }
}

Result:

Leave a Reply

Your email address will not be published. Required fields are marked *