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.