Dynamics 2013 Access to pages with pages is difficult with iframe-based views

I am creating an angular application that works as a web resource on Dynamics 2013.

The application is launched using the button, which is added to the commandContainer using the Ribbon tool, which then calls the Xrm.Internal.openDialog button

All this works fine until I start using objects exposed by Xrm.Page.Data

Basically, my button works in the context of the main dynamics page, however Entities are inside an iframe, which, based on the page I was on, has a different identifier and name.

Therefore, using a simple selector, I cannot get its contentWindow and start using Entities.

The #crmContentPanel always has a few iframes in it, starting from # contentIFrame0 to #contentIFrame (n), and I can never know which iframe is the one that has Entities in it.

What is the best practice related workflow with developing applications in this environment? How can I easily and reliably access the correct frame that contains the objects of the main page and works with them.

Perhaps the script is in the wrong place and needs to be entered into the main content area so that it has direct access to the correct Xrm? How can i achieve this?

In addition, as soon as I eventually manage to access this data, how can I easily transfer this data to my angular application that runs in the dialog box, as from the documentation that I read that only 1 line parameter is allowed for the dialog request, and it has which will be called data. This would not be enough for my application to start using $routeParams . And I do not think that using local or session storage is good practice. What is the right approach in this situation.

Sample code for my script button:

 function runSendSender() { // Content Iframe Entity data: var contentFrameXrm = $('#crmContentPanel') .find("iframe#contentIFrame0...n")[0] .contentWindow['Xrm']; // even if above selector was consistent across pages // I need to send over much more than this one Id :( var data = contentFrameXrm.Page.data.entity.getId(); var src = "/WebResources/concep_/ConcepDynamicsApp/ConcepDynamicsApp.html?data=" + data; var DialogOptions = new Xrm.DialogOptions(); DialogOptions.width = 800; DialogOptions.height = 500; Xrm.Internal.openDialog(src, DialogOptions, null, null, CallbackFunction); function CallbackFunction(returnValue) { } } 

A bit more

When I type the following in the console, I sometimes (accidentally) read the form header:

 $('#crmContentPanel').find("iframe#contentIFrame0")[0].contentWindow['Xrm'].Page.ui.get_formTitle(); 

But the same code from the related function of the web resource cannot access the iframe and errors:

 Can not Cannot read property 'contentWindow' of undefined. 

Why the iframe is not accessible through the script resource and how can I access the correct context and title / id form.

+6
source share
2 answers

The record identifier can be sent to runSendSender as a parameter by the tape itself. Just add the appropriate CrmParameter ( MSDN ) call to the function call.

In your case, the parameter value will be FirstPrimaryItemId ("Provides one GUID as a string for the record being watched.")

After that, you change your function as follows

 function runSendSender(recordId) { ... } 

In addition, avoid internal actions: to open a web resource in a dialog box, you must use the supported method (the link contains information about the transfer of parameters other than data to the resource).

 Xrm.Utility.openWebResource(webResourceName,webResourceData,width, height) 
+3
source

I usually include the following JavaScript file in the header of a custom WebResource that should have access to specific CRM actions / information:

 <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script> 

This gives access to any specific information that is not related to any entity, for example, Xrm.Page.context.getServerUrl() or Xrm.Page.context.getUserId() .

But if you added a layer with your own iFrame on top of the standard entity page, you can definitely access the information under your current context using the following construction:

 window.parent.Xrm.Page.data.entity.attributes.get("name").getValue(); 

Note the window.parent prefix.

+5
source

Source: https://habr.com/ru/post/974878/


All Articles