i write one plugin that change one field on update messege.
in audit history showing each record two time .
once by admin.crm user and once by user that changed a form
*This post is locked for comments
i write one plugin that change one field on update messege.
in audit history showing each record two time .
once by admin.crm user and once by user that changed a form
*This post is locked for comments
Hi,
If you are updating same record, then plugin will execute multiple times..
Instead of triggering plugin after update, execute plugin on pre-update and set field value.. so all update operation will be done in one context and record will be saved once.
here is example how to update record using plugin in per-update, check example 2
Is this plugin updating the same entity? no , Just update itself. (one filed on itself)
If you disable this plugin, do you see any audit record? no if i disable it everything is ok , and just one field in audit history.
If you also have an update plugin, you should have the same problem too.
my simple plugin :
public void Execute(IServiceProvider serviceProvider)
{
// TODO: Implement your custom Plug-in business logic.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = (IOrganizationService)servicefactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
if (context.MessageName.ToLower() == "update")
{
Entity entity;
try
{
entity = context.InputParameters["Target"] as Entity;
entity["myField"] = "something";
if (context.Depth <= 1)
{
service.Update(entity);
}
else
{
return;
}
}
catch (Exception ex)
{
...
}
}
}
Is this plugin updating the same entity? If you disable this plugin, do you see any audit record? Can you share your plugin code?
I just have one plugin. The problem is with the plugin.
A simple plugin that updates a field.
Hi,
Did you check if you have any other workflow/plugin which could be running on update?
I am updating a field at the running the plugin.
I have already added it (context.Depth).
I tried all possible modes. (Change calling user and pre or post update)
In all states, two records show in audit history For any change.
Okay so you are not updating any fields in the plugins?
Make sure you added context depth properties inside plugin.
if (context.Depth > 1)
return;
The plugin only updates one field that is not in the Screenshot.
Any user who changes a form once has a change in his name and once in the name of admin.
plugin message : Update
filtering attribiute : just one field that i want plugin execute when it changed.
plugin run in user's context : admin.crm
Hi Ehsan,
As per my understanding with the screenshot , seems plugins first updating with Admin context which means in plugin registration tool you may set run as Admin user context.
Second update you might be updating again the same record details with initiating user context , which means the organisation service inside plugin has been created with initiating user by which you are updating.
To avoid the issue you should create organization service using the context.userid parameter so that this will be update with only admin user.
And try to avoid passing fields in the entity which you dont want to update.
Is your custom plugin running under Admin user context and in that plugin if you are updating record again then it might cause creating two audit records.
André Arnaud de Cal... 291,711 Super User 2024 Season 2
Martin Dráb 230,458 Most Valuable Professional
nmaenpaa 101,156