Expanding The Capabilities of CRM Portals Part 1 – Dynamically Displaying Controls from CRM Form Section
Web Portals can extend your Dynamics CRM capabilities by offering non-CRM users access to your data through customized web forms. Portals are extremely versatile and offer an infinite number of possibilities in integrating, displaying and manipulating CRM data with a different interface.
Typically, Portal Development involves pulling CRM fields and displaying them in a custom user interface.
Oftentimes this works, but what if the fields that need display can change over time? Of course, you could customize the Portal anytime a change needs to be made, but that would require deployment each time a change was necessary…and unnecessary deployments should definitely be avoided.
This blog post will show you how to set up CRM portals to adjust for dynamic content.
Pulling Dynamic Fields in a CRM Portal
By leveraging the form customization features of CRM, a CRM Administrator can add any number of fields to a single section of a form in order to set what fields are displayed on the portal. The portal will then adjust for the amount and types of the fields and display them in a meaningful manner.
For example, you can create custom portals based off of the “Product” entity. Simply take the fields that you want to be displayed on the portal and add them to a section on the form (I have created two test fields below, “Dynamic Field One” and “Dynamic Field Two”, a string and boolean value respectively, to be added to the Additional Details tab).
I have also created a new product, “TESTPRODUCT”, with both of the dynamic fields populated.
The first thing that needs to be accomplished is to retrieve the field names off of the form. We can use the Query Expression class to grab the XML of the form, and from there we can manipulate the XML to retrieve the field names.
Once we have the XML pulled from the form, we can get the field names and using the field names we can get the values. First we will cut the XML into separate substrings to contain only the data from the tab that we want. Then we will loop through that XML snippet and add each instance of “datafieldname” to a list. This will give us all the field names that are currently on the form section. From there, we will loop through the results, cut the strings to get the field names and add them to a list.
Now that we have a list of all the names of the fields that are on the form, we can create a fetch XML statement, and call the retrieve method to get the values of those fields for a specific record. You will need to loop through and add the attributes separately to the fetch statement.
Once we have each of the attributes and their values, we need to detect the type of the field and add HTML elements to the page from the code behind. For each field type that we have in the list of fields, we need to get the Attribute type and compare the type against each type that can be returned (Decimal, String, EntityReference, Guid, etc.) from the form. Then we can generate a new Panel to display the information, format the returned value, and add that panel to a container on the front end. This is also where we would add CSS style to the fields.
And voila! You can now add any field to that form and have it pulled and displayed straight to the portal.
Creating a separate web portal that pulls data from CRM is a great way to extend the information to non-CRM users. Portals are easy to set up, control, and customize. For additional help setting up your portal, contact our CRM experts at FMT Consultants by filling out the form below.