刷新表单(Ctrl + F5)不会在CRM 2011中触发检索插件

时间:2015-04-01 13:14:17

标签: javascript dynamics-crm-2011

我需要根据entity1的创建更新entity2(数学计算) 而entity1的形式是公开的。

当我刷新entity1表单时,该字段具有旧值,直到我关闭并打开entity1表单(缓存问题)。

我发现它不会触发Retrieve插件。有没有办法通过刷新表单来克服这个问题?

1 个答案:

答案 0 :(得分:0)

首先:最新的CRM有Xrm.Page.data.refresh()来“自动”更新表单数据(更不用说通过插件更改字段时自动刷新的事实)。

如果升级不是一个选项,我会设置一个“观察者”功能,如下所示:

// attach to Form Load event
function keepYourFieldInSync() {    
    setInterval(function(){
        var current = Xrm.Page.getAttribute("yourField");

        // Not shown here, basically get the updated value from server
        var fetched = fetch_yourField_value_from_OData_or_SOAP();        

        if(fetched != current){
            Xrm.Page.getAttribute("yourField").setValue(fetched);

            // if users aren't allowed to set the field by hand, I'd also include this
            // and customize the field to be readonly
            Xrm.Page.getAttribute("yourField").setSubmitMode("never");
        }
    }, 1000); // keep it above 500 to avoid killing the browser
}

我使用这样的“技巧”来识别引号中的状态更改(另一个用户会在此用户处理草稿时激活它)并且它运行良好。