Sometimes when building forms you are going to run into a situation where you may need to set or remove the business requirement of an attribute on a form. This comes in handy when you are using multiple forms for different types of users. For instance, a salesmen may only need the ability to add basic customer information on one screen, but on another screen you may have information not visible to the salesman, such as financial information. This financial information may include fields that MUST be entered by the finance folks. So, what you do in these situations is remove the requirement at the attribute level and add the following code to a page load event on your page:
1 var myAttribute = Xrm.Page.getAttribute("new_MyAttribute");
2
3 //Check to make sure there is an attribute by that name
4 if(myAttribute != null)
5 {
6 myAttribute.setRequiredLevel('required');
7 }
You could also remove the required level by:
1 var myAttribute = Xrm.Page.getAttribute("new_MyAttribute");
2
3 //Check to make sure there is an attribute by that name
4 if(myAttribute != null)
5 {
6 myAttribute.setRequiredLevel('none');
7 }
Or even set it as Business Recommended:
1 var myAttribute = Xrm.Page.getAttribute("new_MyAttribute");
2
3 //Check to make sure there is an attribute by that name
4 if(myAttribute != null)
5 {
6 myAttribute.setRequiredLevel('recommended');
7 }
Hope this quick snippet can help!