Hi,
I wrote a pre-operation plugin where I'd like to prevent any changes to contact's jobtitle.
The Plugin itself is pretty simple:
if (targetEntity.Attributes.ContainsKey("jobtitle")) targetEntity.Attributes.Remove("jobtitle");
and
protected static Entity GetCurrentEntity(IServiceProvider serviceProvider) { var context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext)); return context.InputParameters.GetEntityOf("Target"); }
For testing, I do some JS in account form and force jobtitle to be sent to the plugin:
Xrm.Page.getAttribute('jobtitle').setSubmitMode("always");
As a result, in audit log of a modified contact, jobtitle get's updated anyway.
I'd expected to not update jobtitle (as it is "foo" all the time), but audit log shows:
field | old value | new value |
jobtitle |
foo |
|
fax | 1 |
2 |
=> looks like changing targetEntity somehow modifies the "old value"??
Can anyone guide me on how to prevent specific fields from beeing updated? In real code I want to avoid updates of fields, which have not changed (but are in the attribute collection due to submit-mode "always" or for any other reason) which should be possible by comparing pre- and target image.
*This post is locked for comments