Pre-validation, Pre-operation and Post-operation on Synchronous and Asynchronous plugins in CRM 2011

Hi Everyone, I decide to write something about this topic since I don’t really get it. The Pre-validation stage will allow your plugin to run outside the SQL transaction, that means that the after the form is submitted, but before the record is created is where the plugin runs, the purpose should be to check a condition to allow the record creation.

The Pre-operation stage happens after the validation and before the values are saved into the database, at this point we should be sure that the record can be created, but we are still in time to change some bit and pieces.The Post-Operation operation plugin runs after the values have been inserted/changed in the database. A lot of fancy words, but the problem is that is not as straightforward as it seems.

Basically you are aware that if you use the first two steps the record is not there, so is pointless to look for it in the context (I like to use an early bound approach so I can use Linq queries to filter the data), but when you try to query an entity on a post operation plugin you expect (or at least I was expecting) to find out the record that I just created. Unfortunately is not like that, to manage to retrieve the record you just created you need to run the plugin in an asynchronous way. Otherwise as soon as you query the context (even if the record should already be there) you will receive a funny “null” as the result of the Linq query. Now if you keep that in mind should be easier to sort out weird errors.

NOTE: I wrote this article some time ago, the last paragraph is incorrect. There are multiple ways to perform the record creation and the example was maybe working for some CRM 2011 release.

I just link a couple of article that were useful for me: link1 link2

Programmatically retrieve Date formats from Excel cells

Hi Everyone, I had to fight against this issue, basically I had to retrieve a date from an Excel file and manipulate it as a DateTime. Easier said than done, the content of the cell was an unfriendly double, and I had no Idea on how to convert it. That’s the code that is doing the trick:

This is the article on Microsoft Knowledge base

Dynamics CRM 2011 CrmSvcUtil Filtered entities

When you are writing plugins for Dynamics CRM 2011, is useful to know the CrmSvcUtil.exe. Basically this tool allows you to generate a series of classes for manipulate entities in an early bound stage.

Still I don’t really get the difference between early and late bound (beside the comfort of using the intellisense). But anyway if you are in a context where you want to use the early bound and you will generate the file, is very annoying to have to manage a 6-10MB class files that contains all the entities in the organization (when at the end you will end up using no more than 15 – 20 of them). In that context is very useful to have a way to filter the output of the generated file. I found this article that allows you to do exactly that. I’m using the current version of the sdk, and i didn’t have any problems at linking the dll. Actually is working really well and allows you to filter the generating files (the one that i used in a web service and the one that i used as a plugin/workflow).

Here you can find the Microsoft official guide for the generation of the Entity file.

Here you can find the passages to generate a proxy class and connect to the crm from a web service.

I would like to copy Erik Pool article but i prefer to ask him first since will be an exact copy 🙂 maybe with some comments.