Set field required javascript Dynamics 365

In Dynamics 365, Business Process Flow attributes are just like Form attributes. You can use most of the controls in the same way as you normally do for Form attributes. Let’s look at the most common ones together.

Get Business Process Flow attribute control using Javascript

To get attributes Add “header_process” before schema name of field. Let’s say your attribute schema name is “cm_myattribute“.

Making a field business required or mandatory is one of the most important aspect in the whole business process. Earlier in Microsoft CRM there were two ways to make a field mandatory or business required, one was to mark the field as business required in the form and other was to dynamically make the field business required with help of custom JavaScript code. Now with Dynamics 365 we can make the field business required dynamically without any coding using the business rules.

Select the entity for which you have to implement the business rule. In our case we are using Account entity. Within the selected entity navigate to the section “Business Rule” and open it and click on New.

Set field required javascript Dynamics 365
Set field required javascript Dynamics 365

Now the business rule template should get opened. Here select the dedicated condition for which you have to set or value in a particular field. In our case, we will set the field “Fax” to be mandatory if the field Account Number contains data. Therefore we will add a condition statement which will check the Account Number’s value.

Set field required javascript Dynamics 365
Set field required javascript Dynamics 365

Now as we have our condition ready, navigate to the components section and select “Set Business Required”. Drag and place this component to the IF statement of the condition. In this component select the field which you have to make mandatory. In our case we will select field “Fax” to be mandatory.

Set field required javascript Dynamics 365
Set field required javascript Dynamics 365

Now validate, save and activate the business rule. Navigate to Account entity, enter any valid value in field Account Number. Now you will see that the field “Fax” will be automatically set to mandatory or business required.

Entity Forms now come with security roles. You can select security roles and who should be allowed to see the form. This is helpful in scenarios where we have multiple forms for different departments. Let’s say we have two departments: Customer Service and Sales

Customer Service deals with people, while Sales deals with organizations.

Issue: Sales Dept. wants ‘Account/Company Name’ to be mandatory on “CONTACT” form , while Customer Service wants it to be non-mandatory. Both the departments do not want any change in the form design as it suits both.

Solution: Create/Copy a new contact form for either of the department. I am creating a new form for Sales department and naming it ‘Contact Sales Form’ (this form will be a copy of main information form).

Make the field required using JavaScript in D365 CE

  • July 6, 2020June 30, 2021

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:

Set field required javascript Dynamics 365

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:

Set field required javascript Dynamics 365

Tags:Client Scriptingcolumn requiredD365 CED365 CRMDataverseDynamics 365Dynamics 365 CEfield requiredgetAttributeJavaScriptmake column required in d365 cemake column required in ms crmmake field required in d365 cemake field required in ms crmModel driven appmodel-driven appMS CRMsetRequiredLevel

previousMake field read only using JavaScript in D365 CE

nextShow/Hide tab using JavaScript in D365 CE

0 0 votes

Article Rating

Subscribe

Login

Notify of

Label

{} [+]

Name*

Email*

Website

Label

{} [+]

Name*

Email*

Website

0 Comments

Inline Feedbacks

View all comments