Twitter Image

Open a specific form based on a record attribute

Written by Stéphane Dorrekens
Wednesday, 29 May 2013 12:48

MSCRM 2011 allows multiple forms on the same entity and allows to assign certain forms to the user's security roles; so a certain function can use a given form, another function can user other one and switch between them if the user has access to more than one.
However, if your different forms are record based, meaning a certain status or attribute of your record drives the corresponding form, and not role based, it's a bit more tricky to implement.
You can force a given form via the formid url parameter (http://msdn.microsoft.com/en-us/library/gg328483.aspx), or use the javascript FormSelector (http://msdn.microsoft.com/en-us/library/gg328253.aspx) so this gives a couple of supported paths:

1) Via Javascript
You can add a code like this one to the form Onload event:
var theCurrentFormId = Xrm.Page.ui.formSelector.getCurrentItem().getId( );
var theStatuscode = Xrm.Page.getAttribute("statuscode").getValue();
var theFormid;
if (theStatuscode==1)
 theFormid='GUID1';
 else
 theFormid='GUID2';

if( theFormid!=theCurrentFormId )
{
Xrm.Page.ui.formSelector.items.get(theFormid).navigate();
}

The big drawback is that the form may be loaded twice (most of the time if you have a lot of forms) which is slow and cause a very annoying flicker effect to the end user.

2) Via a specific entity attribute as url
You can add a new ntext attribute of type url to the entity and, when the record is created or updated, compute the url for the record with the valid formid parameter (ie: http://crm/theOrganization/main.aspx?etn=account&pagetype=entityrecord&extraqs=formid%3D7009c1fe-ae99-4a41-a59f-a6f1cf8bfdaf%0D%0A) then store the url in the new attribute. You can easily implement this as a plugin on the form Create and Update events.
Afterwards, if the new field is displayed in a grid; the user can click on that field and get direct access to the valid form for that record.

The issue with that option is that nothing forbids the user to click on other links to this record, which would or give an invalid form, or trigger a flicker if option 1 is implemented. Furthermore, the link url is quite long and there's no way in a grid to have a friendly name for that link.

As neither options fully satisfied the customer, we proposed another option based on url rewriting.
Note this third option is unsupported as this changes some settings on the CRM Web site.

3) Via IIS Url Rewrite
This option uses the Url Rewrite module which is part of IIS.
As this never displays anything to the user until the valid form is displayed; there's not flicker effect and as we only uses one web service call and redirects; the actual final opening is only slowed by less than half a second, vs quite a few seconds in a javascript redirect.

Here's a summary schematic of the url flows

In the below example, the implemented rule redirects the forms for the incident entity.

and here's a sample of the Custom application on 7777 (note that the valid formid is already stored in a custom attribute of the record for that example).

Comments  

 
#2 luigi4235 2015-02-21 13:15
▬▬ι═══════ﺤ -═══════ι▬▬
+++http://thatsafunnypic.com+++
 
 
#1 Dennis 2013-06-21 13:02
Good information