Pre & Post-Entity Images on Update-Plugin CRM 2011

A Robben picture A Robben · Apr 23, 2012 · Viewed 9.9k times · Source

I hope somone can help me with a problem I been trying to deal with over some time now. I have a create plugin and a update plugin. For testing purposes my create plugin (Pre-Operation) does a simple calculation and puts the result on a field after save.

My update-plugin works fine when I register it on the pre-operation and change the fields I have my logic for. HOWEVER if I only change one of those fields (or get other fields dirty on the form)I get an error that the key was not present in the dictionary. I have done my research and seen that you do a check between Pre and Post Entity Image to check what fields have been updated and which not. But what I'm confused about is when I do this I need to regrister my update plugin on Post-opertion, which results to my update not working anymore and if I do service.Update(entity) at the end of my code it gives me another error of infinite loop. On my Update plugin I have made sure that I registerd two images (Pre and Post). I would appreciate if someone can advice me, how to do the checks between pre and post images?

Answer

paramosh picture paramosh · Apr 24, 2012

We need to see your code. But I can provide short explanation what is going on there.
service.Update(entity) call your plugin one more time, because it's another update to entity where your plug in is registered. To avoid this infinite loop you can watch Depth property. Each new call to plugin will increase value of this property.

If you want to know what properties were changed during update, just look into InputParameters. There will be only updated properties values.

Pre-Entity images are available for Update message, but not for Create (it's impossible to have an image before entity instance was actually created). But Post-Entity image presents in case of both Create and Update messages.
So, if you need to know what properties were changed, check InputParameters. You can do this in Pre-Stage plugin. And value, updates in InputParameters will be stored in database, so you don't need call service.Update.