In my last blog post, I have talked about why we need a Naming Plugin and we have done some customization to our Meeting entity for, to remove the Name field from the form. In this blog post I will show you how to write the Naming Plugin.
As stated before, this blog is more showing you the logic and code for generating the entity Name using a Plugin, for general Plugin development or how to create a Plugin from scratch, you can checkout this tutorial provided by Microsoft.
*
So I have created a new Plugin class called “TestNamingPlugin.cs”. The main purpose of this Plugin will be set the Name of Meeting to “With - Time - Place” format.
At the beginning of the class, just some standard checking:
Then we can check it is a Create or Update form, as the behaviour will be slightly different between them. Then call a different function.
In our HandleUpdate function, we just retrieve the entity record, then call the HandleGeneric function.
Here we have done a little trick, as the step we registered is “Pre-operation”, so only the changed attributes will be in our entity, so we need to create another entity with the same type, then retrieve any other information we need from database, then merge those two entities. The merge function is below:
In our Handle Generic function, we will get the details of the fields we will use to make up our Name.
Here are two helper functions we used in our code above:
Now if you can build this Plugin, and register it using Plugin Registration Tool, check out this link if you are not quite sure.
Now after we registered this plugin, and save the record, the name of the record should looks like this:
That’s all for Naming Plugin, hope you find it useful in your next project.
*Image from http://www.dixel.co.il/logo_plugin.jpg