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.

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’)
Like this:
Like Loading...