Friday, 21 April 2017

How to read configuration data in plugins using secure configurations?

Recently, we deployed some custom SharePoint integration with Dynamics CRM which required some custom coding. As usual, we wanted to connect to different Dynamics CRM environments (DEV, TEST, UAT, PROD, etc.). Every time we deployed, we didn’t want to change the code so that it can connect to the correct SharePoint site.

To achieve this there are few options available and we used the Secure Configuration feature available with Plugin Registration tool. There you provide all the configurations like site URLs, usernames, passwords, etc., in XML format and you can access them within the constructor of your plugin.

Your plugin registration will look like this; inside secure configurations box you enter your configurations in xml format.

Your configurations XML would look like this:

  <setting name="siteURL">
  <setting name="DocumentLibName">
  <setting name="SPOUserName">
  <setting name="SPOpassword">
  <setting name="Case_DocLibPath">
  <setting name="Case_Type_Hidden_StaticName">
  <setting name="ContentTypeId">

Here in the constructor of the plugin, you can read the settings you set in the Secure Configuration XML.

public OnUpdateOfCase(string unsecureConfig, string secureConfig)
            XmlDocument doc = new XmlDocument();
            siteURL = SecureConfigHelper.GetConfigDataString(doc, "siteURL");
            DocumentLibName = SecureConfigHelper.GetConfigDataString(doc, "DocumentLibName");
            SPOUserName = SecureConfigHelper.GetConfigDataString(doc, "SPOUserName");
            SPOpassword = SecureConfigHelper.GetConfigDataString(doc, "SPOpassword");
            Case_DocLibPath = SecureConfigHelper.GetConfigDataString(doc, "Case_DocLibPath");
            Case_Type_Hidden_StaticName = SecureConfigHelper.GetConfigDataString(doc, "Case_Type_Hidden_StaticName");
            ContentTypeId = SecureConfigHelper.GetConfigDataString(doc, "ContentTypeId");


No comments:

Post a Comment

How to tackle Concurrent Business Process flows

Dynamics 365 has introduced the new feature of Concurrent Business Process Flows. Here is a couple of good articles on that: http://dev...