Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

TypeError: Xrm.Utility.getGlobalContext is not a function

Posted on by 509

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
    Lee-Martin 509 on at
    RE: TypeError: Xrm.Utility.getGlobalContext is not a function

    It’s a js file 

  • PabloCRP Profile Picture
    PabloCRP 1,086 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
    Torrado 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
    Lee-Martin 509 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
    PabloCRP 1,086 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans