In part one of this series we discussed the built-in mechanism provided by CRM to store plug-in application settings. Based on several comments on the article, I’ve decided to enhance the process by moving the storage of our settings from the plug-in configuration step to a custom CRM entity.
Creating a Custom Entity for Settings Storage
The first step in this process is to create a custom CRM entity which will store our settings. The New Entity form looks like this:
The primary attribute for the Plug-in Setting entity will be configured as follows:
We then add a single attribute that will actually hold our settings information:
Modify the main form to allow entry of the Plug-in Name and Settings information then publish the new entity and we’re ready for business. Here is how we populate a plug-in settings record:
Modified Plug-In Configuration Class
The PluginConfiguration class created in the previous article has been modified slightly to retrieve our settings from the CRM database instead of using the normal plug-in configuration methods.
Note: The constants at the beginning of the class will need to be modified to match the entity and attributes you created on your system.
Putting PluginConfiguration to Work
The only change made to the usage of the PluginConfiguration class I the requirement that we call RetrieveSettings before attempting to access any properties found within the settings attribute:
string TaskPrefix = PluginConfiguration.GetConfigDataString("TaskPrefix");
Note: Since we need a connection to CRM to retrieve settings from the database, you will need to locate the code that retrieves settings after the code that has initiated a connection to the CRM web service.
By moving the settings from the Plug-in step configuration to the CRM database we’ve reduced the maintenance level required to store our settings in a central location. There will be a slight performance hit since we have to retrieve a database record, but I don’t think it will be huge.
I’ll place the source code for the modified pluginconfiguration class on my blog so you may download it and add it to your next plug-in project.