0

I've an HTML web resource in Dynamics CRM on-premise environment. It is saved as new_htmlpage1, now at a click of Custom button I'm opening this HTML web resource. I've added ClientGlobalContext.js.aspx as reference in HTML webresource as well. But still I am receiving error that GetGlobalContext is not defined

Below is my HTML source code.

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

<script type="text/javascript">

function tempContext(){

 if (typeof GetGlobalContext != "undefined") {

            var userName = Xrm.Page.context.getUserName();

            alert(userName);

            return;

        }

}
</script>
</head>
<body onload="tempContext()">
</body>
</html>

Here is the walkthrough from Microsoft that I am following, but still unable to get GlobalContext.

Please let me know what I am missing here.

Cedan Misquith
  • 1,134
  • 9
  • 20
Mohsin A.
  • 153
  • 2
  • 18

1 Answers1

0

The path to ClientGlobalContext.js.aspx is a relative path (relative to the location of your web resource), so ensure that you navigate up the necessary amount of times. E.g. one of the following might be what you need to use, depending on your web resource:

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

You should then call the function GetGlobalContext() from JavaScript to get access to the global context.

Right now you are trying to call Xrm.*, which is not available. As the documentation for the GetGlobalContext function states:

Including a reference to ClientGlobalContext.js.aspx does not make the Xrm object available in HTML web resources. Therefore, scripts containing Xrm.* methods aren’t supported in HTML web resources. parent.Xrm.* will work if the HTML web resource is loaded in a form container. However, for other places, such as loading an HTML web resource as part of the SiteMap, parent.Xrm.* also won’t work.

Henrik H
  • 5,747
  • 1
  • 21
  • 33
  • I just wanted to illustrate that it is relative to the path of your web resource. What do you mean that it is not working? What is the path to your web resource? Can you see in developer console whether the file is loaded or not? – Henrik H Jul 01 '19 at 12:45
  • I mean all three formats don't worked for me. I've also checked in Console and the file ClientGlobalContext.js.aspx is not loading. – Mohsin A. Jul 01 '19 at 12:52
  • Great, then you know that you still need to properly load `ClientGlobalContext.js.aspx`. You can get back to me once you have that working. You will need to navigate up from the location of your web resource, which is why I have been asking you about what the path to your web resource is. – Henrik H Jul 01 '19 at 13:43
  • my webresource path is `http:////WebResources/new_documentuploader` – Mohsin A. Jul 01 '19 at 13:44