1

I have an Angular html page that has script reference to the javascript. In the Javascript I am using Xrm object to make certain actions like Xrm.webApi.retrieveMultipleRecords etc..

This Angular Html Web resource is loaded as part of SiteMap. The Angular Html web resource also have script reference to "ClientGlobalContext.js.aspx" and able to access Xrm object.

If I remove the aspx script reference the Xrm object is undefined. Microsoft docs mention that this script reference doesn't make the Xrm object available but in my case it's exactly what it is doing.

Then I tried removing the "ClientGlobalContext.js.aspx" reference and started using parent.Xrm object and everything seems to be working fine again. But the Microsoft docs again said that parent.Xrm will not work if loading an HTML web resource as part of SiteMap which exactly is my scenario and seems to be working.

So need to know what I should do as I don't want to use any methods that's going to be deprecated.

Here is the link to the Microsoft docs: Screenshot of the issue

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/getglobalcontext-clientglobalcontext.js.aspx

jasonscript
  • 5,189
  • 1
  • 23
  • 39
  • Are you attempting to access the form via the Xrm. Syntax, or the Global Context, Xrm.Utility.getGlobalContext(), or both? – Daryl Jul 31 '20 at 10:53
  • It is not the form. I am trying to access the Xrm object within a Html Web Resource that loaded by the SiteMap. Without use of the "ClientGlobalContext.js.aspx" script reference, the Xrm object is undefined (which contradicts to the screenshot). If i use parent.Xrm then i am able to make the webApi calls but again this contradicts to the screenshot hightlighted part as well. So want to know what's the right approach here. – Sai Krishna Jul 31 '20 at 12:08

1 Answers1

0

I had a similar problem using Xrm.WebApi object in a Web Resource as well.

See here: Using Xrm.WebApi method in Web Resource opened in a new window

The short answer is, is that the methods rely on JavaScript constants that are only loaded on the CRM pages. You can work-around the issue by providing your own constants, and copy the values from window.opener.top.

jasonscript
  • 5,189
  • 1
  • 23
  • 39