Kaspar Christensen a consultant from Denmark published an cool paper on JScript that I swiped some of for TechEd in a session that Jeff Louckes and I did. With very little work, you are able to move data from a HTML Page or ASPX page in an iFrame to the main CRM form. This allows for some interesting data integration scenarios.

The one outlined at TechEd was of an internal credit application that assigned a score based upon a number of different items in other internal systems. It then posted a credit score to each account. That data needs to be imported into the CRM system, but doin a traditional data import would be difficult and time consuming. :-)

So we render the credit score for each account in an iFrame in CRM and have the value from the HTML Page put back on the CRM form.

Here is the orginal form before anything is clicked.

Here it is after clicking on the Save Credit Score and Appove Credit Buttons.

This was of course all was inspired by this commerical I hate that is blasted all over the TV...

 

The example below contains an entire html page that can be used as an iFrame target. The example contains three methods.

The first function is taking the value from a text field and putting it back into a field new_iframeresponse on the CRM Form.

function Button1_onclick() {

var oCrmForm = parent.document.forms[0];

if (oCrmForm) {

oCrmForm.all.new_iframeresponse.DataValue = document.all["Text1"].value;

oCrmForm.Save();

}

}

The second function is toggling the selected value of a drop down field new_iframeresponsecode on the CRM Form.

function Button2_onclick() {

var oCrmForm = parent.document.forms[0];

if (oCrmForm) {

if(oCrmForm.all.new_iframeresponsecode.DataValue == 1) {

oCrmForm.all.new_iframeresponsecode.DataValue = 2;

}

else {

oCrmForm.all.new_iframeresponsecode.DataValue = 1;

}

}

}

The third function simply reloads the CRM Form.

function Button3_onclick() {

parent.window.location.reload();

}

The coolest part of this code to me is:

var oCrmForm = parent.document.forms[0];

Which is how we would address the CRM Form. So with out the variable, which would look like:

parent.document.forms[0].all.new_iframeresponse.DataValue =

As opposed to method inside the CRM Form itself:

crmForm.all.new_iframeresponse.DataValue =

So if you want to play with this yourself, you can download the attachment here and install on your DEMO box. To install:

  1. Unzip Zip File
  2. Import XML File
  3. Create Directory called Samples inside of C:\Program Files\Microsoft CRM\CRM Web\
  4. Copy the HTML File into that directory
  5. Publish the Customizations in CRM

Enjoy and thanks Kaspar for sharing.