2

我将尽我所能解释这一点,请随时根据需要要求澄清。

使用 IE10、CRM Online 和 RU12。

我正在玩子网格并让它们刷新。考虑下面的脚本,我从 MSDN 批发了它(并包装在一个 try/catch 块中)

function start() {
    try {
        var controls = Xrm.Page.ui.controls.get(isSubGrid);

        if (controls.length > 0) {

            var subGridNames = "";
            for (var i in controls) {
                controls[i].refresh();
                subGridNames += (" - " + controls[i].getName() + "\n");
            }
            alert("The following subgrids were refreshed: \n" + subGridNames);
        }
        else {
            alert("There are no subgrid controls on the current form.");
        }
    }
    catch (ex) {
        alert(ex);
    }
}

function isSubGrid (control)
{
    return control.getControlType() == "subgrid";
}

那里没有什么特别的 - 获取所有类型的控件subgrid(这会按预期返回 10 个元素)并调用refresh()它们。

然而,这在第一次调用时始终失败refresh()

异常细节相当简单

TypeError: Unable to get property 'Refresh' of undefined or null reference

这表明control[i]此时在循环中调用时为空

for (var i in controls) {
    controls[i].refresh();//error thrown here - suggests controls[i] is null
    subGridNames += (" - " + controls[i].getName() + "\n");
}

但是我可以看到它不为空(并且具有refresh预期的方法)。

在此处输入图像描述

我可以通过使用使它工作setInterval

function waitAndThenRefresh(gridname) {
    var grid = Xrm.Page.ui.controls.get(gridname);
    var intervalId = setInterval(function () {
        if (grid === null || grid._control === null || grid._control._element === null) {
            return;
        }
        if (grid._control._element.readyState === 'complete') {
            window.clearInterval(intervalId);
            if (grid != null) {
                grid.refresh();
            }
        }
    }, 1000);
}

但这非常可怕,更不用说没有解释 SDK 调用不能按预期工作。

所以我想问题是:有没有其他人看到这个问题?或者你可以在另一个实例上复制它吗?我错过了什么吗?SDK 中没有任何内容表明您需要将调用推迟refresh到内部控件readyStatecomplete?

4

2 回答 2

1

The code block you are using,

for (var i in controls) {
    controls[i].refresh();
    subGridNames += (" - " + controls[i].getName() + "\n");
}

should be replaced with the following:

for (var i in controls) {
    i.refresh();
    subGridNames += (" - " + i.getName() + "\n");
}

or:

for (var i = 0; i < controls.length; i++) {
    controls[i].refresh();
    subGridNames += (" - " + controls[i].getName() + "\n");
}

You are getting the exception because controls[i] is undefined in your case, i being the control (the element of the array controls).

于 2013-03-17T14:39:26.977 回答
0

我问了我的一个 CRM 伙伴。他说这个问题取决于新的刷新引擎。据他说,这是一个错误,但不是真的。如果我做对了,刷新已经过重新设计以适应新的永久保存功能。

于 2013-03-20T20:53:59.037 回答