-->

How to identify Header Section in CRM Form?

2019-08-12 05:28发布

问题:

Is there a way to tell if the section is a header in CRM Form?

We're on Microsoft Dynamics CRM 2016 and I have a requirement to disable all fields on the Contact form when a certain condition is met. I'm using the code below and so far the code is working.

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);
  }
}

However the reason I ask, special for header fields, you need to put header_ before the field name in order to get to the header fields. For example header_name. Since our CRM Manager likes to put different fields on the header, it'd be nice to automatically disable the header fields instead of manually change it.

Is there a way to tell if the section is a header in CRM Form?

回答1:

Basically every field in the form has to be in a section except header. So this is helpful in this case as we have to identify the fields in header & disable it.

I have used forEach iterator to check each control and if that control does not have a Parent which is a section - then its a control in header, so disable the control.

Xrm.Page.ui.controls.forEach(function (control) {
            if(!control.getParent()){
              control.setDisabled(true);
            }
        });

Reference: getParent