Softstuff Consulting
My occasional musings of a technical nature
  • Send us a message
  • About Softstuff Consulting
  • Privacy Policy
  • Main Website
Dynamics365 , JavaScript

Access a Dynamics365 embedded webresource

by Ian Blair December 27, 2019 2 Comments

Embedded webresources on a Dynamics365 form are very useful. They can provide screen layouts and functions that the out of the box solution cannot. 

This example shows how a message can be posted directly to the webresource, and this makes it useful for passing live updates from the parent Dynamics365 page without having to go through the save, reload cycle.

More information on how to pass messages between pages is available here.

var iframe = Xrm.Page.ui.controls.get("<<Name Of WebResource>>");
if (iframe != null) {
    var ifrm = iframe.getObject();
    if (ifrm != null) {
         var ifrmContent = ifrm.contentWindow;
         if (ifrmContent != null) {                    
                    ifrmContent.postMessage('my data', "*");
         }
    }
}

This code can be placed in an onchange event of a Dynamics365 field so that when it changes the embedded webresource can instantly update. The webresource will require an event handler to receive the messages passed to it. This will also circumvent and cross page scripting issues.

The above code finds the content window of the embedded resource using the standard Dynamics365 JavaScript API which then makes it available for standard JavaScript. In this case we use the postMessage function to send data,

The destination is a ‘*’ which is not recommended and in almost all cases should be the URL of the Dynamics365 system to prevent the possibility of malicious attacks, although Dynamics365 security will be in effect.

cross page scriptingdymamics365javascript

  • Previous Sending messages between web pages without falling foul of cross-page scripting errors5 years ago
  • Next Format numbers in Javascript5 years ago

2 Replys to “Access a Dynamics365 embedded webresource”

  1. Mike M says:
    January 5, 2020 at 2:13 pm

    Thanks, this is exactly what I was looking for in the project I am working on. I managed to get access to the child elements on the iframe and this had me stumped for a while. I was getting ready to give up.

    Reply
  2. CRMGod says:
    January 7, 2020 at 10:31 pm

    ifrmContent.getElementById(xxx) worked perfectly, easy way to convert from Dynamics speak to plain JavaScript

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How to make your Powershell scripts more annoying
  • What motherboard is in my PC
  • A Dynamics365 plugin thought experiment
  • Registering a Dynamics365 plugin and I get an error
  • Going back in time with Dynamics365

Categories

  • Bootstrap
  • C#
  • CSS
  • Dot Net Core
  • Dynamics365
  • JavaScript
  • Powershell
  • T-SQL
  • Thoughts
  • VBScript
  • Visual Studio
  • Windows
  • Xamarin

Recent Comments

  • S0ftStuffB055 on Call a Dynamics365 workflow from JavaScript
  • Siva on Call a Dynamics365 workflow from JavaScript
  • TC Sharpe on Throw exceptions in Dynamics365 workflow plugins, or don’t
  • BigOwl on Throw exceptions in Dynamics365 workflow plugins, or don’t
  • CRMGod on Access a Dynamics365 embedded webresource

Archives

  • January 2021
  • May 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • June 2019
  • May 2019
  • February 2019
2025 Softstuff Consulting. Donna Theme powered by WordPress
  • Twitter