Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

audit history on update messege plugin

(0) ShareShare
ReportReport
Posted on by 215

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 

Untitleda.png

*This post is locked for comments

  • Verified answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 17,021 on at
    RE: audit history on update messege plugin

    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

    crmbook.powerobjects.com/.../developing-a-plug-in

  • ehsan af Profile Picture
    ehsan af 215 on at
    RE: audit history on update messege plugin

    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)

                       {

                         ...

                        }

              }

    }

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: audit history on update messege plugin

    Is this plugin updating the same entity? If you disable this plugin, do you see any audit record? Can you share your plugin code?

  • ehsan af Profile Picture
    ehsan af 215 on at
    RE: audit history on update messege plugin

    I just have one plugin. The problem is with the plugin.

    A simple plugin that updates a field.

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: audit history on update messege plugin

    Hi,

    Did you check if you have any other workflow/plugin which could be running on update?

  • ehsan af Profile Picture
    ehsan af 215 on at
    RE: audit history on update messege plugin

    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.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: audit history on update messege plugin

    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;

  • ehsan af Profile Picture
    ehsan af 215 on at
    RE: audit history on update messege plugin

    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

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: audit history on update messege plugin

    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.

  • Suggested answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 17,021 on at
    RE: audit history on update messege plugin

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans