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.
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.
ifrmContent.getElementById(xxx) worked perfectly, easy way to convert from Dynamics speak to plain JavaScript