Thursday, July 12, 2012

How to Build an HTML/JScript Configuration Web Resource for Microsoft Dynamics CRM 2011

Web Resources can be used to create an interface to allow end-users to easily configure your solution after it's been installed.  This is ideal for storing keys and other sorts of registration or configuration information related to the solution.

Download the Sample here:

For step-by-step instructions on how to install a configuration page (this one is already installed) and work with it from an end-user standpoint you can visit Mahender Pal's blog here:

Building the Sample

1. First you must unzip the download file and install the included zip file
2. Next you must Import and Publish the into your Microsoft Dynamics CRM 2011 instance.  Your instance can be On-Premise or Online.


After you install the solution there are only two main components worth noting.  
1. A custom entity used to store configuration data.  I chose to use a custom entity instead of an XML file or other mechanism due to the ease of securing and manipulating the data.  The data is easy to secure because, as a custom entity, it uses the standard role-based security already included in CRM and by default will only be available to administrators.  The data is also easier to manipulate because if stored as an XML web resource it is stored in the content attribute of the webresource entity.  This means that you have to follow these steps to work with the data.
- un-encode the content attribute (it is stored as a base-64 encoded string)
- parse the XML 
- update the values
- re-encode the attribute data in base-64
- make an update call
It's just more complicated.

2. An HTML webresource that includes jscript that contains the GUI for working with the configuration data and also has jscript web service calls wired up inside that facilitate saving and retrieving the data.
The logic is easy:
When page loads it checks for a configuration record with a specific name.  If it finds the record it will load the data into the GUI.  
When the update button is pressed it checks if the record existed or not and creates it if it didn't exist otherwise it will update the record.

Source Code Files

  • - Download Zip File
  • - CRM 2011 Unmanaged Solution File

No comments:

Post a Comment