How to make a field required on a form in CRM using Javascript

Posted on Posted in MS CRM 2011, MS Dynamics, MS Dynamics CRM

Sometimes when we want a field to be required when saving data in Microsoft Dynamics CRM depending on selecting an other field.

For example we have a dropdown of categories and on selecting a certain category we want certain fields to required (must have some value).

We can do this by using Javascript on our form

Go to Settings>Customizations>Entities>Select required Entity

Entity>Forms>(select form) Main>Open form

1

Once Form is opened go to Form Properties

2

On Events tab we can add a JavaScript file to do any checks we require

3

Click on +Add to add a new file

4

Select Type to Scripts and then add your code in Description box, give it a name and all ready.

On changing selection should call a method….

function rokhri_category_onchange() {

    CallMyMethod();

}

Funcion CallMyMethod(){

                Alert(‘hello there’);

}

Save and publish..

Now go to your entity and try it and a message will appear on saving your item with specified category.