web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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?

I have the same question (0)
  • Suggested answer
    PabloCRP Profile Picture
    1,088 on at

    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

  • Lee-Martin Profile Picture
    515 on at

    Thanks

    can I add that script tag into a ha webtrespurce?

  • Suggested answer
    Torrado Profile Picture
    1,270 on at

    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.

  • PabloCRP Profile Picture
    1,088 on at

    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

  • Lee-Martin Profile Picture
    515 on at

    It’s a js file 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 45 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 36

#3
Satyam Prakash Profile Picture

Satyam Prakash 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans