dynamics crm - CRM Javascript How to Disable Fields on the Form Header - Stack Overflow

We're on CRM 2016 and I have a requirement to disable all fields on the Contact form when a certai

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

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);
Share Improve this question edited Jul 20, 2018 at 2:23 jasonscript 6,1783 gold badges30 silver badges45 bronze badges asked Jul 19, 2018 at 19:44 ichachanichachan 6672 gold badges12 silver badges36 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 5

I have to add "header_" into my field names in order to make it work

Xrm.Page.getControl("header_mycustomfield").setDisabled(true);

Like answered in another SO thread, you can disable all the controls in header in single shot without hard coding the names.

To optimize your code in question for disabling form controls entirely, use this:

Xrm.Page.ui.controls.forEach(function (control) {
            if (control.setDisabled) {
                control.setDisabled(false);
            }
        });
// Tested On CRM v8.2

// lock a header control
Xrm.Page.getControl("header_statuscode").setDisabled(true);

// this won't work if statusreason is hosted in the header section
Xrm.Page.getControl("statuscode").setDisabled(true);

// lock all controls on form, including header controls
Xrm.Page.ui.controls.forEach(function (control) {
    if (control.setDisabled) {
        control.setDisabled(true);
    }
});

Using formContext you can also disable it.

 if (formContext.getControl("accountid").getAttribute()!= null)  
     formContext.getControl("accountid").setDisabled(true); 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742419936a4440480.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信