
I one field in two locations on the form.
I know if I pull up the properties of one field, I can set it to read only WITHOUT the change effecting the same field in the other section.....
I need to do this with code, but I'm not quite sure how to grab the section/field rather than just the field.
I know I can do Xrm.Page.getAttribute("field name").getValue(); to acquire the field value, BUT I want to make sure I get the correct field in the section I specify.
Please help thanks!
*This post is locked for comments
I have the same question (0)Something like this should work. Just pass the name of the section that the field is in and the name of the field. I used ctrl.getName().search(field) because CRM appends a number to the end of duplicate fields.
i.e. If you add new_field to the form it is named new_field. If you add a second new_field it is named new_field1.
The only issue is if your field name is a substring of another field name. i.e. account and new_account
//set specified field read only in specified section
function setReadOnly(section, field) {
var ctrlName = Xrm.Page.ui.controls.get();
for (var i in ctrlName) {
var ctrl = ctrlName[i];
if (ctrl.getName().search(field) != -1) {
alert(ctrl.getParent().getName());
var ctrlSection = ctrl.getParent().getName();
if (ctrlSection == section) {
ctrl.setDisabled(true);
}
}
}
}