JavaScript Required

We're sorry, but we doesn't work properly without JavaScript enabled.

Looking for an Expert Software Development Team? Take two weeks Trial! Try Now

Alternate Approaches to the Plugins Unsecured and Secured Configs (Using JSON File in Plugin Assembly)

Alternate Approaches

Secured and Unsecured Config are used to keep the configuration data that is being used inside the plugin code and we don’t want to have those as the hardcode in the code. As and when there is a lot of custom extension required in a project, we require having the ample amount of plugin registered for functionality extension and at the same time, it becomes difficult to keep the configuration data in code repository as it would need to have multiple Config files maintained. On the other hand, if we don’t keep Config inside the code repository, there might be chances of losing those on the application crash.

While working, if Dynamics CRM Consultants are using Unsecured/Secured Config to just to avoid hard coded in our plugin code and for better code structure, rather than using Unsecured/Secured Config, we can have a JSON file inside the plugin project.

But, as the separate file cannot be registered to the CRM server, we need to go through the following steps to embed the file into assembly itself.

Steps:

  • 1. Put all the configurations into JSON format and segregate those into that JSON file either categorizing by entity name or event or both. Like, if we have an unsecured configuration with a plugin step registered on the Account entity and also have a configuration on the opportunity entity, we can define our JSON as follows.

    { "Account":[ { "uniqueNamePrefix":"IND" } ], "Opportunity":[ { "uniqueNamePrefix":"IND" } ] }
  • 2. Add the JSON file into the plugin project and go to the properties of the included file to set the Build Action as “Embedded Resource”.

    Alternate Approaches
  • The following function is used to read the file. File name in the below code should be replaced with Plugin assembly name.<folder in which file is kept inside>.<Resource Name or JSON file name>

    In the below example, “OrganizationName.Cme.Dyn.Plugins” is the assembly name. “Data” is first folder and “JSON” is folder into “Data” and JSON file is kept there itself.

    Alternate Approaches
  • 4. Retuned Byte stream from the above mentioned function can be converted into JSON format using JSON serialize to get the values from the configurations

Conclusion

Rather than using Unsecured/Secured configurations, we can have JSON files embedded with assembly to keep all the hardcode values which can be easily maintained in the code repository.

You may like to read on Nurture an Everlasting Bond with Your Customers with Dynamics CRM’s Enhanced Customer Service Hub!

 
Ast Note

Some of our clients

team