XRM SetDisable 并非每次都有效

XRM SetDisable doesn't work every time

我正在使用 CRM,我需要使用 javascript 锁定表单中的所有字段(大约 300 个)。

我使用这个功能:

var allAttributes = Xrm.Page.data.entity.attributes.get();
for (var i in allAttributes) {
    var myattribute = Xrm.Page.data.entity.attributes.get(allAttributes[i].getName());
    if (myattribute != null && myattribute != undefined && myattribute != '') {

        var myname = myattribute.getName();
        var myControl = Xrm.Page.getControl(myname);
        if (myControl != null && myControl != undefined && myControl != '')
            myControl.setDisabled(true);
    }
}

对于其中的大多数,它有效,但某些字段在我的表单中仍然是可编辑的。 我在 Chrome 中逐步调试它,似乎在我的函数后未锁定的字段上,我做了“myControl.getDisabled()”,并将其设置为 true。但字段未锁定在表单上。

这些字段中没有任何其他 javascript 运行。我试图将我的函数调用延迟 10 秒(使用 setTimeout),但没有任何变化。

知道如何锁定每个字段吗?

我认为你的功能可以重构为:

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

试试这个重构,如果之后它不起作用请命名你正在工作的实体并且字段未锁定。