Pavel Topinka
Pavel Topinka

Reputation: 95

MS Dynamics 365 - Iframe - Access Xrm - permission denied

I have problem with integration between MS Dynamics CRM and my javascript app.

I need to setup communication between Opportunity page and my app in the iFrame.

Problem is that when I need to access XRM object in the page, I alway get Access Denied Error

I tried:

parent.window.Xrm.Page.data.entity.attributes.get(“stateCode”).getValue();

When I call this function from IE Dev tool then it works fine. But from my JS app it throws Access Denied.

I read a lot about the iFrame integration but none works with MS Dynamics 365.

Upvotes: 0

Views: 1422

Answers (2)

Piotr Gaszewski
Piotr Gaszewski

Reputation: 343

The problem with "Access Denied" may be related with CORS policy if your JavaScript app is hosted outside Dynamics environment. To avoid this problem on one of my projects we were using postMessage API (https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) instead of direct access to DOM model to send/receive messages between CRM form and IFRAME site.

I've written blog article describing how to make it work (unfortunately it is in Polish, but maybe some automatic translation will help;)): http://xrmlabs.piotrgaszewski.pl/?p=455

Upvotes: 2

Henk van Boeijen
Henk van Boeijen

Reputation: 7918

The parent.window of the HTML web resource that is loaded in an IFrame on a CRM form is actually not the form's window. In fact, in Turbo Forms mode it is not possible to access the form's window using the DOM.

There are a few other options:

  1. Pass the entity id and name to the HTML web resource (MSDN) and query other data needed on your custom page using the web api.
  2. Access the web resource from a script on your form and push the data to your custom page. (Note: do not use document.write as it will not work on every browser.)
  3. Turn turbo forms off (Settings -> Administration -> System Settings -> General -> Use legacy form rendering). This is not recommended, because you will turn it off for all entity forms and it will not provide a durable solution.

Upvotes: 1

Related Questions