Home › Dynamics 365 Customer Engagement (CRM) › Using Xrm.Page in Dynamics 365 HTML Web Resource
Dynamics 365 Customer Engagement (CRM) · Nov 7, 2016 · 1 MIN READ

Using Xrm.Page in Dynamics 365 HTML Web Resource

In Dynamics 365, you can add HTML Web Resources with JavaScript. You may want to use Xrm.Page features, but if you try to do this, you get the error that “Xrm” is undefined.

To get around this, you need to use GetGlobalContext function. Add the script below to your web resource:

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

Add the code:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
    <script type="text/javascript">
        function ButtonClicked() {
            var userName = Xrm.Page.context.getUserName();
            alert(userName);
        }
     </script>
</head>
<body>
    <button onclick="ButtonClicked()">Submit</button>
</body>
</html>

Save and publish. Open an account:

Press Submit. You will see the user name displayed:

 

 

Carl de Souza
Keep learning. Keep building.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.

Subscribe on YouTube →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

Leave a Reply

Your email address will not be published. Required fields are marked *

Carl de Souza
KEEP LEARNING. KEEP BUILDING.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.