[英]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.