D365 – Understanding Plug-in Pipeline

What is a Plugin?

  • Plug-in is a class library or set of classes. And when you compile a set of classes you get something called DLL file or Assembly file. This assembly file has some custom code and we register these assemblies in some server side event.
  • You can run plug-in code on common events such as Create, Update, Delete, Assign, etc . Of specific record type. In dynamics terminology event and message are same thing.
  • For example: On entering revenue field of a Contact, you would like to perform some tax related calculation automatically. So here the event is “On Update” and the entity “Contact”. This means the trigger is on update of a Contact record, where we can register the event.

What happens on server?

Scenario:

  • Let us say the client creates a contact record.
  • The information goes to the Main Event (say Create event) on the server. This even creates a record and pushes the data into the database.
  • A response will be sent back from the database through the main event back to the Client where the page will be reloaded / refreshed. Now you will see the contact record as saved contact.
  • Now again the Client updates the Revenue details on that contact.
  • The information goes to the Main Event (which is now Update event).
  • The platform takes care of the data and response comes back to the Client where the page is reloaded / refreshed.

So every time a client changes something, there is a round trip happening. In this case there is no custom code involved. Also, you cannot modify the main event and is handled by the platform.

The system, however, gives to the ability to write custom code before the Main Event and after the Main Event.

Let us say you want to run a custom code before the Contact record is created. You can write your custom code as class library, upload it to the server and register before the Main Event (i.e. Contact Create).

Similarly if you want to run your custom code after the creation of the Contact record, you can register after the Main Event.

Remember, the main event does not change. But you can have Pre validation stage and Pre Operation stage before the main event and Post operation stage after the main event.

So if you want to make changes to the data before it is inserted or updated in the database, you can use the Pre-Validation and Pre-Operation stage. If you want to perform changes to the data after the record is inserted or updated in the database and before it reaches to the Client, you can use the Post-Operation stage.

This is called as plugin pipeline.