简体   繁体   English

Dynamics CRM Javascript制作表单只读-TypeError:control.getDisabled不是函数

[英]Dynamics CRM Javascript making form read only -TypeError: control.getDisabled is not a function

Attempting to make the price list form and price items form read only and using the below java script however keep getting the following error; 试图使价目表和价目表为只读,并使用下面的java脚本,但是始终出现以下错误; One of the scripts for this record has caused an error. 该记录的脚本之一导致了错误。 For more details, download the log file. 有关更多详细信息,请下载日志文件。 TypeError: control.getDisabled is not a function at makeFieldsReadOnly TypeError:control.getDisabled不是makeFieldsReadOnly的函数

Using Dynamics CRM 2016 and this JS runs on load of the form 使用Dynamics CRM 2016,此JS在表单加载时运行

function onLoad() {
    var formType = Xrm.Page.ui.getFormType();

    if (formType == 2)
        makeFieldsReadOnly(); }


function makeFieldsReadOnly() {
    var controls = Xrm.Page.ui.controls.get();
    for (var i in controls) {
        var control = controls[i];
        if (!control.getDisabled()) {
            control.setDisabled(true);
       }
    } }

Any suggestions on why this may be failing , working fine in CRM 2011? 关于为什么可能会失败的任何建议,在CRM 2011中可以正常工作?

Not all the controls you are iterating over can be disabled and thus the code is failing. 并非所有要迭代的控件都可以被禁用,因此代码将失败。 It throws an error when it tries to execute getDisabled on a control, which does not have this function declared. 尝试在未声明此函数的控件上执行getDisabled时,它将引发错误。

This can be fixed by checking if the necessary functions exist on the control first: 可以通过首先检查控件上是否存在必需的功能来解决此问题:

function onLoad() {
    var formType = Xrm.Page.ui.getFormType();

    if (formType == 2)
        makeFieldsReadOnly(); }


function makeFieldsReadOnly() {
    var controls = Xrm.Page.ui.controls.get();
    for (var i in controls) {
        var control = controls[i];
        if (control.getDisabled && control.setDisabled && !control.getDisabled()) {
            control.setDisabled(true);
       }
    } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Dynamics 365 CRM上使用Xrm Object将表单设置为只读 - Set form read only using Xrm Object on Dynamics 365 CRM Dynamics CRM已读/未读表单 - Dynamics CRM Read/Unread Form Javascript 错误 - addPreSearch 不是一个函数 - Dynamics CRM - Javascript Error - addPreSearch is not a function - Dynamics CRM Dynamics CRM:用于日期更改的JavaScript onClick函数 - Dynamics CRM : JavaScript onClick Function for Date change Dynamics CRM JavaScript 平均值 - Dynamics CRM JavaScript Average 恢复Dynamics CRM表单更改(按用户)使用JavaScript - Revert Dynamics CRM Form Changes (by user) Using JavaScript 检索快速查看表单值 - Dynamics CRM JavaScript - Retrieve Quick View Form Value - Dynamics CRM JavaScript 通过 JavaScript 在 Dynamics CRM 表单中创建静态 URL 超链接 - Create static URL hyperlink in Dynamics CRM form via JavaScript 禁用选项列表字段功能会重置值 Dynamics crm 4.0 Javascript - Disabling picklist field function resets value Dynamics crm 4.0 Javascript Dynamics CRM 2015:如何获得创建的Web资源按钮以引用添加到表单的Javascript库中的函数? - Dynamics CRM 2015: How do I get a Web Resource button I created to reference a function in a Javascript Library I added to the form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM