Making a Field Mandatory Based on Forms via JavaScript in Dynamics 365

Hello Readers!

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).

Mandatory 1

Go to form properties.

Create a web resource and add it on load.


Here’s the JavaScript I used:

function getFormName()


var Form = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

if (Form == ‘Sales Contact Form’)










Hope you find it helpful!

Happy CRM’ing!

One thought on “Making a Field Mandatory Based on Forms via JavaScript in Dynamics 365”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s