Thursday, 28 May 2009

Change Field/Attribute requirement at runtime using javascript

Some times you come across with the situation when you have to make field mandatory on the form at runtime. Let say on selection of one field other field become required and if selection change field become business recommended or not required anymore.

On possible way is to use if-else statement to check if field.DataValue == null or not and respond accordingly. But following code can be used to make fields not required, required and business recommended.


crmForm.SetFieldReqLevel("fieldname",0);// set field to not required
crmForm.SetFieldReqLevel("fieldname",1); // set field to required/mandatory
crmForm.SetFieldReqLevel("fieldname",2); // set field to business recommended
Hope this helps. Please drop some comments if script is helpful.

Note: The above code is not supported by Microsoft.

6 comments:

Anonymous said...

nice post.

Anonymous said...

Superb article .Easy way to achieve my requirement.Nice

Saran said...

Iam facing one issue while Converting Custom Entity to Lead.The activites of Custom Entity is not copied to Lead.Plz help

sam said...

worked perfectly fine :) thank u

Anonymous said...

perfect way to fix my problem :)
keep it up!

sureshbopitiya said...

The field on Form becomes business recommended when I change the related field, but if I remove the value in the related field the other field does not revert back to not required. I need it to change back to not required. I hope you can help and look forward to your answer!

Post a Comment