In Microsoft Dynamics CRM 2011 you have the option to create additional customized forms for any entity. So how can you use this to open specific forms and where do you get all the information?
Creating a new form
Since this article is all about custom forms I’ll just start at the beginning. Let’s say that for the account entity we’d like to create a new form that displays a little less than the normal form. To create this new form go to solution and open the entity as normal and navigate to the “Forms” menu. This will show you only two forms one being Main and the other Mobile. Clicking new here will open up a popup with the usual designer options. Customize the form, pick a name and save and it will be added to the list.
What’s in a GUID?
Like everything that is a record/entry in CRM (which a form actually is), has a GUID. The easiest way to get the GUID of any form is to open up the form designer for that specific form and pressing the F11 key. This will set the window to full screen and allow you to take a gander at the URL. Here you’ll see a string like this:
http://crm:5555/test/main.aspx?appSolutionId=%7bFD140AAF-4DF4-11DD-BD17-0019B9312238%7d&etc=1&extraqs=formtype%3dmain%26formId%3d389BED7C-1569-47F0-A879-7486B40268F5%26action%3d-1&pagetype=formeditor
Tip: The method of getting the GUID here can be used in many places in CRM. When you’re stuck and need a GUID for something check out the URL by pressing F11 in the window and hovering over the top to display the URL.
Take note of the extraqs which provides you with a way to pass additional parameters to specific pages. In the extraqs you’ll see a “formId” parameter. You’ll also notice that extraqs is riddled with % signs, these are used for URL encoding, all of the parameters for extraqs have to be encoded. You could decode the string by using “decodeURIComponent(encodedUri);” the decoded extraqs look like this:
formtype=main&formId=389BED7C-1569-47F0-A879-7486B40268F5&action=-1
So that’s where the form id can be found. You could also crawl the exported customizations.xml, but that would require a few extra steps. After you exported you can look for a
tag within the form definition for the right GUID.
Building the new URL
So to start building a new URL which opens a record in a specific form we need to know what a normal url looks like. To do that the F11 trick can be applied after opening a record. This shows the following:
This URL also has an encoded extraqs that we could use, after decoding it looks like this:
?_gridType=1&etc=1&id=%7bE45EB53E-384A-E011-847B-000C29BC0C32%7d&rskey=202087116
A few things can be noticed here:
- The id is double encrypted for some reason
- There is a second entity type code to be found in the extraqs
- There is an mystical rskey
Note that the SDK points out that you should use ETN (entity type name) rather than ETC (entity typecode) in all cases where a url is constructed.
All that is needed here is to add the formId in the extraqs and it all works. The encoded extraqs looks like this:
%3F_gridType%3D1%26etc%3D1%26id%3D%257bE45EB53E-384A-E011-847B-000C29BC0C32%257d%26rskey%3D202087116%26formId%3D389BED7C-1569-47F0-A879-7486B40268F5
And the full url:
The result is a slimmed down version of the account form that was made especially for the demo. Note the “New form” that is now selected in the navigation menu.
The possibilities from here on are pretty broad, you could imagine doing things like creating specific forms for i-frames or reusing the same form several times in a single window.
While playing around with this I found some caveats that you should be aware of before doing this:
- It’s a little tricky to get the Xrm object from an IFrame
- Beware of the usual recursive IFrames in IFrames
- When using an IFrame of the same entity in the same form the default form might switch
- It’s not possible to simply set the form to not be displayed as an option in the navigation form, a possible work-around is adding some JavaScript to perform this task.
Enjoy
-Alex


