Development 101: Note to self – PostRetrieveMultiple behaviour in PlugIn

Last week I was working on an integration project where I had to integrate SharePoint Online and CRM Online. Today my project manager approached me and told me that the connector I wrote was not working as expected. The job of the connector was to show a list of documents inside a portal.
Some of the documents were stored on SharePoint Online; instead of storing the document in CRM only the link to the document in SharePoint was stored. Clicking the document link should trigger a download of the document.

Instead of the triggering the download within the portal through CRM to SharePoint, the user received a hyperlink file. *strange*

What I implemented within CRM was the following: I had written a plugin that implemented the PostRetrieve and the PostRetrieveMultiple events. The events checked if a Note (annotation) was containing a document. In case the Note was containing a document (isdocument==true), the link was fetched from the documentbody of the Note entity and the document was retrieved from SharePoint using the link and inserted in the documentbody of the Note entity that was going to be returned.

For a single document (PostRetrieve) the mechanism worked like a charm.
For retrieving a list of documents (PostRetrieveMultiple) the mechanism didn’t work because it turned out that CRM doesn’t fill the documentbody when retrieving a list of records using the object model.  * grumble *