Post Data from a Dynamics CRM Form to an iFrame

HTML web resources can be embedded into a CRM form within an iFrame. Often you'll need to send data to and from the embedded HTML page. Here's how.

If you need to send data from an HTML page to a CRM form, you can use window.parent to access the Xrm namespace. For example, a user may enter a value into an input field on your embedded HTML page which could then update a value on a CRM form automatically by using:

Sending data the other way (from a CRM form to an HTML resource) is slightly more complicated.

Firstly, when customising your form and adding the embedded HTML resource, ensure that cross-frame scripting is not disabled (which it is by default). If this option is left checked you'll receive a sandboxed script cross-origin error message in the browser console, and the script won't load on the form.

Secondly, set up the data you want to send from your CRM form in JavaScript. This example sends a contact's first and last name in their respective onChange() events:

More on window.postMessage() can be found on MDN here.

Finally, configure your HTML page to accept and process messages from your CRM form. Place the following script tag in your HTML's body:

Here's the finished example:

3 comments:

  1. Hi, this has helped me out greatly. However, I'm trying to populate 28 fields on iFrame. It works when I step through the debugger, but not when I don't step through the code. This makes me think there is a timing issue or something. is there something I should be adding when trying to post with that many fields? I'm pulling my hair out over this lol. Thanks.

    ReplyDelete
  2. i really like this article please keep it up.
    Webdesign

    ReplyDelete
  3. Thanks for your insight for your fantastic posting. I’m glad I have taken the time to see this. Online Quran Academy

    ReplyDelete