Hi,
We were using the below function in CRM 2011 for disabling all the fields in the form.
function makeAllAttributesReadOnly() { 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(); Xrm.Page.getControl(myname).setDisabled(true); } }
However this function in CRM 2013 was giving us setDisabled field is undefined JavaScript error.
As it turned out it was because of the StateCode (Status) field in CRM 2013.
Modifying the above code to leave this particular field resolved the issue.
function makeAllAttributesReadOnly() { 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(myname == "statecode") { return; } Xrm.Page.getControl(myname).setDisabled(true); } }
Hope it helps.
i used Xrm.Page.ui.controls.forEach(function(c,i){c.setDisabled(true);}); and didn’t get this error.
LikeLike