17th December 2008

Microsoft Dynamics CRM Audit Plugin Tool

Database auditing tools are extremely valuable when you need to be able to determine who made a certain change or when trying to figure out how a particular value was set.  Microsoft Dynamics CRM does not have any native auditing beyond storing who created a record and who modified it.  There is no way to see which fields have changed and what their previous values were.

However, we can easily create our own auditing plugin tool and easily audit all fields or just specific fields for specific entities.  Note: All code samples and documentation contained in this post assume that you have access to the CRM server directly, that the user account running the CRM Async Service has permissions to read the registry on the CRM server, and that the Prefix in the Customization tab in System Settings is the default “new.”

First of all, we need an entity to store the audit records.  We could store the audting records in their own SQL database; however, we have chosen to store the records in CRM so that we can use native features of CRM to find data, such as Advanced Find and CRM Reports.  Download the custom audit entity here.  Refer to CRM documentation on how to import and publish the custom entity.

Secondly, we will store a few configuration settings in the registry on the CRM server.  Download the .reg file here and make the necessary changes to it before you import it into your registry.

Lastly, we need to register the plugin. We have used the free plugin developer tool that comes with the CRM SDK and it can also be downloaded in its compiled version at the end of this post. You can download the source code for the plug-in here and screen shots are below.

Steps to register the plugin


Step 1: Register the .dll file.
CRM Audit Plug-in 1

Step 2: Browse to the .dll file and then register the AuditPlugin class into the database.  Note, it is best to do this directly on the CRM 4.0 Application server.
crmaudit2.jpg

Step 3: Plugin should register successfully.  If you get any errors, refer to CRM support forums for troubleshooting suggestions.

crmaudit3.jpg

Step 4: Register a Create step.  Fill in the form as shown in the screen shot below.  As you are typing you will notice that there is some auto-suggest or intellisense built-in.  As shown in this example, we are registering the Audit Plugin to run anytime an account is created in CRM and the audit plugin will have access to all attributes on the account record that is created.

  crmaudit4.jpg

Step 5: After creating the Create step your screen should look like the following.

crmaudit5.jpg

Step 6: Register the Update event.  As shown in the screen shot below we are telling CRM we want our plugin to run any time any attribute on an account record changes.  What will happen is each time a user clicks Save or Save and Close on an account in CRM, if any of the attributes have changed they will be passed to our audit plugin which will create audit records in CRM.

crmaudit6.jpg

Step 7: This steps shows how you need to register Post and Pre Images for each Step as well.  This allows the audit plugin to know what the value was before it changed and what it is after the change.

crmaudit7.jpg

Step 7b: A sample of creating a Pre image.  Note, you will need a Pre and Post image for all Update steps and only a Post image for any Create steps.

crmaudit8.jpg

You can see that it is pretty simple to register the plugin to be able to audit any entity or even any attribute that you want. 

Resources:

CRM Plugin Registration Tool

CRM Audit Plugin Package (includes everything mentioned)

This entry was posted on Wednesday, December 17th, 2008 at 3:58 pm and is filed under Microsoft .Net, Microsoft Dynamics CRM. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

There are currently 25 responses to “Microsoft Dynamics CRM Audit Plugin Tool”

Why not let us know what you think by adding your own comment! Your opinion is as valid as anyone elses, so come on... let us know what you think.

  1. 1 On January 27th, 2009, Timur I. Alhimenkov said:

    Good work! Thank you!
    I always wanted to write in my site something like that. Can I take part of your post to my blog?
    Of course, I will add backlink?

    Regards, Timur I. Alhimenkov

  2. 2 On January 28th, 2009, Faisal Fiaz said:

    Hi,
    I have been trying to deploy this plugin but it is coming up with an error message “Could not capture post image Post - The given key was not present in the dictionary.” Am I missing something?
    Regards
    Faisal

  3. 3 On March 11th, 2009, admin said:

    I apologize for not getting this out sooner. It turns out I had uploaded an incorrect version of the custom audit entity. I will post the correct one shortly. Thank you for the feedback.

  4. 4 On June 4th, 2009, AndrewBoldman said:

    I really liked this post. Can I copy it to my site? Thank you in advance.

  5. 5 On July 6th, 2009, CrisBetewsky said:

    Hello! Thanks for the post. It is really amazing! I will definitely share it with my friends.

  6. 6 On September 25th, 2009, trandate online said:

    Great!
    —————————————

  7. 7 On November 1st, 2009, houttymub said:

    Other variant is possible also

  8. 8 On January 25th, 2010, samsung lcd said:

    Ah, the land of the free!
    You have the right to free speech as long as you speak English.

    best regards, Greg

  9. 9 On March 30th, 2010, Linta said:

    I am also getting the error “The given key was not present in the dictionary”. Any updates?

  10. 10 On March 30th, 2010, admin said:

    I am no longer working on this particular feature. Please refer to a post at http://blogs.engage2day.com/?p=90. They will likely be releasing a better version next month as well.

  11. 11 On March 31st, 2010, affestInnonia said:

    I agree, a useful phrase

  12. 12 On May 29th, 2010, Anonymous said:

    I am the first time on this site and am really enthusiastic about so many good articles. I think it’s very good.

  13. 13 On July 12th, 2010, vin number check said:

    Nice find! That comments form is a really nice example of using textures.

  14. 14 On September 22nd, 2010, Robbie said:

    nice post.

  15. 15 On September 27th, 2010, Polwor said:

    cool blog, I bookmarked you.

  16. 16 On October 2nd, 2010, Allena Tozzi said:

    Thank u a lot for that wonderful blog submit.

  17. 17 On October 14th, 2010, Bonus said:

    I will experiment my thought, your post bring me some good ideas

  18. 18 On October 14th, 2010, Learn said:

    I honestly appreciate your weblog. the posting is in actuality the most effective on this worth while topic. thank you.

  19. 19 On October 18th, 2010, spanien said:

    It took me a while to search on the web, only your site unfold the fully details, bookmarked and thanks again.

    - Kris

  20. 20 On October 28th, 2010, Chauncey said:

    Great stuff.

  21. 21 On November 24th, 2010, brett sucliffe said:

    Thank you so much, wonderful job! Just the information I needed.

  22. 22 On November 29th, 2010, sql monitoring said:

    Thanks for the one of the best blogs i have encountered in a while.

  23. 23 On December 1st, 2010, ebytes said:

    Took me time to read all the comments, but I seriously enjoyed the write-up. It proved to be Quite helpful to me and I’m sure to all the commenters right here It’s always great when you can not only be informed, but also entertained I’m positive you had fun writing this article.

  24. 24 On December 22nd, 2010, Wen said:

    I appreciate the info.

  25. 25 On November 19th, 2011, Rosaria Howe said:

    This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It’s the old what around comes around routine ..

Leave a Reply

  • Links

  • Calendar

  • February 2012
    S M T W T F S
    « Jan    
     1234
    567891011
    12131415161718
    19202122232425
    26272829