In the previous post I described the Customization Aware Web Resource (CAWR) approach.
This approach allows a dynamic reflection of certain customization changes in custom Microsoft Dynamics CRM client (Web Resource, Mobile app, Portal form etc.) as it query and apply metadata properties to relevant form controls.
In this post, I’ll demonstrate an actual implementation of the CAWR approach using SOAP, for those of you who use Microsoft Dynamics CRM 2011 to 2015. In the next post, I’ll replace SOAP with Web API.
You can download an unmanaged solution containing the working sample demonstrated in this post. This solution was exported from MSCRM Online (2016) but you can easily extract the solution file and get to the actual Web Resources.
I’ll start with the final demo result – an HTML Web Resource containing a simple Lead creation form:
This doesn’t look much, but looking at the actual form HTML, you can see that the form elements contain no characteristics beside id.
Since this is a Customization Aware Web Resource, all of the settings are retrieved and applied dynamically according to the Lead entity metadata.
The following metadata attributes are dynamically retrieved and applied to relevant form elements:
- Field type (Single line of text, Money, Boolean, OptionSet) used to determine form element’s validation type and UI
- Text field format (String, URL, Email) used to determine element’s validation type
- Field description used as Tooltip text and validation hint
- Field display name used as element title
- Numeric field values range used to limit input and as validation hint
- Field requirement level indicated by asterisk and to block invalid form submit
- OptionSet field options used as HTML select control options
- Boolean field default value
Some Bits & Bytes
- CreateLead.js – general orchestration
- JQuery.js – bind and query DOM elements
- jquery.validate.js – form validation
- SDK.MetaData.js – query MSCRM metadata. This library can be found in the SDK.
- Sdk.Soap.js – abstracting SOAP communication. This library can also be used to query MSCRM metadata.
- Sdk.Lead.js – model Lead entity. This library was generated by the Sdk.Soap.js framework
The most interesting bits are located in the dyn_CreateLead.js web resource:
The retrieveLeadMetadata function receives an array of required entity attributes, query each attribute metadata and bind it to the form control:
The bindFormControl function apply type specific and general metadata characteristics:
- The SDK.MetaData.js method of querying metadata is not the most efficient technique available. Although more complex, the RetrieveMetadataChangesRequest allows more detailed querying, as well as change tracking
- The SDK.Metadata.RetrieveEntity will return all (~200) Lead entity attribute in one request. Performance wise, If you are only using few entity attributes in your Web Resource, consider multiple SDK.Metadata.RetrieveAttribute requests instead.
- Ideally, this CAWR approach will be implemented in a small utility library in the future. Given enough community interest, I’ll publish such library on CodePlex.
In the next post I’ll demonstrate similar functionality using Web API endpoint instead of SOAP.
Live Long and prosper