0
votes

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.

1
try this way <script src="clientGlobalcontext.js.aspx"></script>Nachiket
I tried with this approach as well, but not working.Mohsin A.

1 Answers

0
votes

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.