In addition to showing and hiding fields in CRM 4.0, an additional technique many of us used was to change the requirement level of a field based on the value of another field. Again, this was an unsupported customization but very, very common.
Setting the Requirement Level ( CRM 4.0 )
In my research, I have found several techniques to set the requirement level:
Set the .req property:
// No requirement crmForm.all.new_field.req = 0; crmForm.all.new_field.setAttribute("req", 0); // Recommended crmForm.all.new_field.req = 1; crmForm.all.new_field.setAttribute("req", 1); // Required crmForm.all.new_field.req = 2; crmForm.all.new_field.setAttribute("req", 2);
SetFieldReqLevel method
// No requirement crmForm.SetFieldReqLevel("new_field", 0); // Required crmForm.SetFieldReqLevel("new_field", 1); // Recommended crmForm.SetFieldReqLevel("new_field", 2);
Setting the Requirement Level ( CRM 2011 )
Thanks to the new and improved CRM 2011 JavaScript object model, we can now set the requirement level like this:
Xrm.Page.getAttribute("new_field").setRequiredLevel("none"); Xrm.Page.getAttribute("new_field").setRequiredLevel("recommended"); Xrm.Page.getAttribute("new_field").setRequiredLevel("required");
Getting the Requirement Level ( CRM 4.0 )
The CRM 4.0 JavaScript object model has a built-in property on all fields that allows you to get the requirement level:
var reqLevel - crmForm.all.new_field.RequiredLevel;
Getting the Requirement Level ( CRM 2011 )
CRM 2011 gives us a corresponding method to get the requirement level of a field:
var reqLevel = Xrm.Page.getAttribute("new_field").getRequiredLevel();
It returns a string: “none”, “recommended”, or “required”
The CRM Migration Assistant converts the above CRM 4.0 JavaScript to the proper CRM 2011 equivalent which will move your code from Unsupported to Supported.