问题描述
当我向字段注册一个OnChange函数时,如果该字段在服务器端的插件上更新(在Dynamics Crm 2015上),它将被触发
When I register an OnChange function to a field, it gets fired if the field is updated on a plugin on the server side (On Dynamics Crm 2015)
可以
示例代码:
1。客户端:
Xrm.Page.getAttribute("org_myfield").addOnChange(function () { alert("org_myfield was changed") });
2。服务器端:
internal void OnPreUpdateRequest(org_myentity target, org_myentity preImage)
{
target.org_myfield = "some value";
}
3。结果(保存记录并且插件完成运行之后):
3. Result (after saving the record and plugin finished its run):
"org_myfield was changed"
所需结果:不应触发警报。
推荐答案
我相信这就是您要获得的:
1.用户在此字段上进行更改时,调用JavaScript on change函数;
2.保存记录时,插件也可能会更改字段的值;
3.如果插件更改了字段值,请跳过JavaScript函数。
I believe this is what you are trying to get:
1. When user makes change on this field, call the JavaScript on change function;
2. When the record is saved, a plugin might change the value of the field as well;
3. If the field value is altered by the plugin, skip the JavaScript function.
如果这是正确的,我可以这样尝试:
从字段中删除 onChange
事件,而在中检查字段状态表单的onSave
事件。
使用 Xrm.Page.getAttribute( org_myfield)。getIsDirty()
确定用户是否对领域。它只会在客户端检查更改,因此不会受到插件的影响。
If this is correct, I would try this way:
Remove the onChange
event from the field, instead check the field status in onSave
event of the form.
Use Xrm.Page.getAttribute("org_myfield").getIsDirty()
to determine whether the user makes any change on the field. It only checks the changes on client side so it won't be affected by plugin.
这篇关于在服务器端更新字段后防止触发OnChange函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!