I had a perfectly functioning Case form that displayed the email message of an Email To Case queue. We just changed our CRM deployment to Claims based authentication (IFD) with ADFS and now I receive the error Access Denied when trying to access the innerHTML of the IFrame. (Code Below)
function DoOnLoad()
{
var isemailcase = Xrm.Page.getAttribute("caseorigincode").getValue();
var x = Xrm.Page.ui.controls.get("IFRAME_EmailBody").getObject();
var y=(x.contentWindow || x.contentDocument);
var element = Xrm.Page.getControl("description");
if (isemailcase == 2) {
if (y.document)y=y.document;
var attr = Xrm.Page.data.entity.attributes.get("description");
y.body.innerHTML = attr.getValue();
element .setVisible(false);
}
}
I did some research and found that I cannot talk directly to the IFrame, I have to use Cross Domain Communication with messages. I found an example that I tried to modify to my requirements and cannot make it work. Furthermore, I get no errors so I do not know what I am doing wrong. My guess is that I an writing to the innerHTML after the IFrame is loaded and so the new HTML body is not showing. I am just not very good with Javascript... can someone help me figure this out??? Thank you so much. Here is my code:
Form Properties OnLoad:
function DoOnLoad()
{
var isemailcase = Xrm.Page.getAttribute("caseorigincode").getValue();
var x = Xrm.Page.ui.controls.get("IFRAME_EmailBody").getObject();
var element = Xrm.Page.getControl("description");
if (isemailcase == 2) {
var attr = Xrm.Page.data.entity.attributes.get("description");
x.contentWindow.postMessage(attr.getValue(), "*")
element .setVisible(false);
}
}
Form Properties OnSave:
function receiveMessage(e) {
var x = Xrm.Page.ui.controls.get("IFRAME_EmailBody").getObject();
var y=(x.contentWindow || x.contentDocument);
if (e.origin == 'https://freya.jensenonline.com' || e.origin == 'https://jdscrm.jensenonline.com'){
y.body.innerHTML = e.data;
}
}
window.attachEvent("onmessage", receiveMessage);