Thursday, October 02, 2008

Passing data from a Microsoft CRM custom form to an IFrame web app running under Microsoft CRM 4.0

Sounds simple doesn’t it? Well it is kind of, but finding the solution was a bit of a pain…

As you probably know CRM customizations support IFrames – which are the only way to have true integration in the CRM UI (as per the current latest version which is 4.0). The “only way”, at least, the way I have figured to do this – is to pass this data across via the querystring, that is, append it to the URL.

You can do this using (unfortunately) JavaScript. You override the OnLoad event for the CRM form in customizations (form properties) and the code looks something like the following:
var myData=crmForm.all.crm_field.DataValue;
//Append the variable to the aspx page.
var URL=crmForm.all.IFRAME_crm_my_form.src;
// pass the URL to the IFRAME
crmForm.all.IFRAME_crm_my_form.src=URL + '&querystring=' + myData;
I need to explain the above script a bit.

crm_field is a type that belongs to the entity. This might be a custom entity or a CRM one, it doesn’t matter.
IFRAME_crm_my_form is the schema name for the custom IFrame (ASPX page). We simply get the current URL so that we can append the querystring.

I'd be interested in hearing any other ways of solving this problem...

No comments: