【问题标题】:CRM Javascript How to Disable Fields on the Form HeaderCRM Javascript 如何禁用表单标题上的字段
【发布时间】:2018-07-19 19:44:45
【问题描述】:

我们正在使用 CRM 2016,我需要在满足特定条件时禁用联系人表单上的所有字段。这是我使用的代码

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

代码运行良好,但由于某种原因我无法访问标题上的字段。不知何故,getControl 总是为标题字段返回 null。页眉的所有字段都没有被锁定,但页脚本身是默认锁定的,我无法解锁。

是否可以禁用 CRM 表单中的标题字段?我是否需要找到一种方法来解锁表单上的标题?我尝试使用以下代码禁用该字段本身,但没有运气。

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

【问题讨论】:

    标签: javascript dynamics-crm dynamics-crm-2016


    【解决方案1】:

    我必须在我的字段名称中添加“header_”才能使其正常工作

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

    【讨论】:

      【解决方案2】:

      就像另一个SO thread 中的回答一样,您可以一次性禁用标题中的所有控件,而无需对名称进行硬编码。

      要优化您的代码以完全禁用表单控件,请使用:

      Xrm.Page.ui.controls.forEach(function (control) {
                  if (control.setDisabled) {
                      control.setDisabled(false);
                  }
              });
      

      【讨论】:

      • 其实我也在问这个问题。
      【解决方案3】:
      // 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);
          }
      });
      

      【讨论】:

      • 虽然此代码可能会回答问题,但提供有关此代码为何和/或如何回答问题的额外上下文可提高其长期价值。
      【解决方案4】:

      使用 formContext 你也可以禁用它。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-23
        相关资源
        最近更新 更多