Prevent firing of OnChange function after field is updated on server side

江枫思渺然 提交于 2019-11-28 05:14:53

问题


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)

Can this behavior be prevented (In a supported way)?

Example code:

1. Client side:

Xrm.Page.getAttribute("org_myfield").addOnChange(function () { alert("org_myfield was changed") });

2. Server side:

internal void OnPreUpdateRequest(org_myentity target, org_myentity preImage)
{
    target.org_myfield = "some value";
}

3. Result (after saving the record and plugin finished its run):

"org_myfield was changed"

Required result: The alert should not be fired.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/47079719/prevent-firing-of-onchange-function-after-field-is-updated-on-server-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!