Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

TypeError: Xrm.Utility.getGlobalContext is not a function

(0) ShareShare
ReportReport
Posted on by 515

I'm upgrading some js code and I'm trying to replace this 

Xrm.Page.context.prependOrgName("myfile");

with this

var context = Xrm.Utility.getGlobalContext();

context.userSettings.prependOrgName("myfile");

However i'm getting this error

TypeError: Xrm.Utility.getGlobalContext is not a function in functionName

This is a js web resource that I'm trying to run it in.The js is ran onload

Has anyone seen this before?

  • Lee-Martin Profile Picture
    515 on at
    RE: TypeError: Xrm.Utility.getGlobalContext is not a function

    It’s a js file 

  • PabloCRP Profile Picture
    1,088 on at
    RE: TypeError: Xrm.Utility.getGlobalContext is not a function

    yeah

    whe you say webresource do you mean to a HTML or a JS file?

    try opening console dev tools form your browser and write that line of code and it should return an object

    pastedimage1621979085112v1.png

    if is just a JS file that you want to set on a form and you can't then you should rise a ticket to Microsoft

  • Suggested answer
    Torrado Profile Picture
    1,270 on at
    RE: TypeError: Xrm.Utility.getGlobalContext is not a function

    Hello,

    What is the version of Dynamics 365?

    In order to troubleshoot, you can open debugger (pressing F12) and run the code directly from the console to check what is available.

    Please follow this guide as example: carldesouza.com/.../

    Hope this helps you.

    Please mark the answer as verified if helpful. That will help others in future.

  • Lee-Martin Profile Picture
    515 on at
    RE: TypeError: Xrm.Utility.getGlobalContext is not a function

    Thanks

    can I add that script tag into a ha webtrespurce?

  • Suggested answer
    PabloCRP Profile Picture
    1,088 on at
    RE: TypeError: Xrm.Utility.getGlobalContext is not a function

    Hi, if you are using that in a webresource might be just context that does not nothing about Xrm object...

    you cand add this tag

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

    now in your script could be in same html or external JS

    <script type="text/javascript">

    var Xrm;

    (function(){

    Xrm = Xrm || parent.Xrm;

    })

    function yourAwesomeFunction(){

    var context = Xrm.Utility.getGlobalContext();

    }

    </script>

    here more detailied

    community.dynamics.com/.../typeerror-xrm-utility-getglobalcontext-is-not-a-function

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,233 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,982 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans