It is by going down into the abyss that we recover the treasures of life. Where you stumble, there lies your treasure.
Joseph Campbell
The CRM forums are a great resource for learning interesting solutions and problems in Microsoft Dynamics CRM
I read this interesting gotcha/CRM Quirk this week about a CRM developer who had written a plugin which was triggered on the RetrieveMultiple event on his custom entity. The user was wondering why his plugin was not being triggered when the user ran a report using FetchXML.
RetrieveMultiple Plugins, What, Why and How?
So you can have plugins which trigger on RetrieveMultiple for an entity. Some readers are thinking why would you want to do that?
Reasons like
- Translate data held in the CRM database
- Exclude data from RetrieveMultiple queries
- Log RetrieveMultiple requests
- Calculate some fields in the retrieve from other entities
- Decrypting encrypted fields
There are lots of other reasons, but they give you an idea. The user wouldn’t even know a plugin had run because they would just receive the results as normal.
The retrieve multiple is triggered in CRM when the user
- Runs an advanced find
- User clicks on a view (e.g. active accounts)
- Quick search
- Associated views
- Plugins doing retrieve multiples
- Console apps doing retrieve multiples
What about reports and FetchXML
So why don’t reports and FetchXML trigger the RetrieveMultiple plugin
The answer was explained in this forum post answer by CRM legend David Jennaway who is a CRM MVP, when I was starting in CRM development David had a fantastic CRM blog which I followed avidly and still do, but but unfortunately for the CRM community David rarely writes any blog posts these days (2 post in 2014).
Reports do not trigger plugins. SQL reports bypass CRM completely, and Fetch reports also bypass the plugin pipeline
Just to clarify the last post, in CRM 2011 fetch queries are submitted via the RetrieveMultiple message, whereas in CRM 4 they were submitted via the Fetch message and (bizarrely) you could handle them in plugins on the Execute message