Updating Microsoft CRM from an iFrame Page


 


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.

UpdateCRMForm.zip

Comments (8)

  1. Susan says:

    Hi There,

    I have an iframe in my order form which calls an asp.net application web page which has a grid on it with some entity records.

    My problem arises when an item is added on the crm Form entity the grid should also be updated automatically.

    But in my case I need to press the refresh button on the CrmForm only then the datagrid in the crm Form is updated.

    Please suggest some solution.

    I am not able to reload the iframe again

  2. prakash says:

    while transferring values from Iframe to CRM

    form am getting error ‘Access Denied’.

    Can anyone suggest for this?

    Regards

    prakash

  3. Ben Vollmer says:

    Did you enable cross site scripting?

  4. Susan says:

    Hi,

    I am also facing the same kind of problem.

    I have a custom asp.net application page called on an IFrame.

    I have enabled cross frame scripting in the iframe but still i get the same error "access denied".

    can someone suggest some solution???

  5. Ajit says:

    I am also facing the same problem.

    Please suggest some solution…

  6. Paul says:

    I had the same access denied issue but came across this post:

    http://blog.alistairl.org/archive/2008/09/02/3870.aspx which solved it for me. The key part is to create a virtual directory within CRM and ensure the URL is not the redirected one. I found that once I had done both of these steps it worked.

    Hope this helps.

  7. Aad says:

    Maybe worth mentioning in the instructions for the not so technical readers like myself that one needs to adjust the Iframe URL from localhost:5555 to the CRM URL of your deployment.. Runs beautifully now, many thanks! Aad

  8. Aad says:

    Hi Ben,

    Ik keep getting 0.all.new… is null or not an object, what am I doing wrong? I tried oCRMForm variable approach and directly with parent.document.forms[0].all.new_iframeresponse.DataValue = but I keep getting the same error.. Please help!

    Aad

    aad@cubeconsulting.nl