We're on CRM 2016 and I have a requirement to disable all fields on the Contact form when a certain condition is met. This is the code that I use
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes) {
var myattribute = Xrm.Page.data.entity.attributes.get(attributes[i].getName());
var myname = myattribute.getName();
if (Xrm.Page.getControl(myname) != null) {
//alert(myname);
Xrm.Page.getControl(myname).setDisabled(true);
}
}
The code works perfectly except for some reason I cannot ever get to the fields on the header. Somehow getControl always returns null for the header fields. All fields on the header are not locked, but the footer itself is locked by default and I'm unable to unlock it.
Is it possible to disable header fields in CRM forms? Do I need to find a way to unlock the header on the form? I tried disabling the field itself with below code but no luck.
Xrm.Page.getControl("mycustomfield").setDisabled(true);