Dynamics CRM 365 – clearOptions()


For Dynamics CRM 365,

Xrm.Page.getControl(arg).clearOptions() method will implicitly call OnChange event of the CRM OptionSet Attribute. This causes one UI behavior which some times might confuse Users, if OptionSet field is defined Mandatory.

Take a example of the Form which has OptionSet field placed on it. And you have JavaScript triggers on Page Load which basically wanted to control the items in the OptionSet attribute based on Security Role of the user or any similar logic.

Now most common practice is we remove all items by calling clearOptions() method on CRM Control and then add the desire items to same Control using addOption() method.

Prior to Dynamics CRM 365, this would work without any problem. However in Dynamics CRM 365, once the form is loaded without User doing anything it will show up , Red Circle (Validation Failure) for Option Set field.

image

This Validation error might confused some User as why are they shown error when they have not yet started entering data.

To avoid this there small trick that works well in this scenario, just remove the Mandatory required level before calling clearOptions() and apply it back after.

E.g.

Xrm.Page.getAttribute(‘new_quotingcustomer’).setRequiredLevel(‘none’)
Xrm.Page.getControl(‘new_quotingcustomer’).clearOptions();
Xrm.Page.getAttribute(‘new_quotingcustomer’).setRequiredLevel(‘required’)

3 thoughts on “Dynamics CRM 365 – clearOptions()

  1. Hi – Do you have a version of “TreeViewForParentChildEntity_1_1_Manged” for CRM 2015/16? It is a useful tool and we are upgrading from 2011!

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Connecting to %s