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:
<Settings>
<setting name="siteURL">
<value>https://xxxx.sharepoint.com/sites/CRM-DEV/Cases/</value>
</setting>
<setting name="DocumentLibName">
<value>CaseDocumentLibrary</value>
</setting>
<setting name="SPOUserName">
<value>SPCRMIntegrationUser@xxxxx.com.au</value>
</setting>
<setting name="SPOpassword">
<value>xxxxx</value>
</setting>
<setting name="Case_DocLibPath">
<value>/sites/CRM-DEV/Cases/CaseDocumentLibrary</value>
</setting>
<setting name="Case_Type_Hidden_StaticName">
<value>g5dc149027cf444eae73dfec7bd07885</value>
</setting>
<setting name="ContentTypeId">
<value>0x012000E8517D690891E149A88FC509298C39B300BA883DF9E383BA47AD69DC71A7712B76</value>
</setting>
</Settings>
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();
doc.LoadXml(secureConfig);
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");
}