Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Xrm.Utility is throwing an error

Posted on by Microsoft Employee

We are currently updating Dynamics from v8.2 to v9. While updating the JS I've been trying to use the command Xrm.Utility.getGlobalContext() however I keep getting an error saying 'Utility' is undefined.

I've tried using the execution Context but this dosnt seem to work either.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Xrm.Utility is throwing an error

    Your code contains few errors. I fixed it. Try to use the following code instead:

    function MyFunction(ExecutionContext) {

    var myVariable = Xrm.Utility.getGlobalContext();

    }

    According to the documentation Xrm.Utility.getGlobalContext should be there - docs.microsoft.com/.../xrm-utility

    Also, why do you use "depreciated" when it's proper to use "deprecated" in this context. Microsoft uses "deprecate" (not "depreciate") - docs.microsoft.com/.../important-changes-coming

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Xrm.Utility is throwing an error

    Looks like thats already depreciated and will be removed in the next year. Is there a solution that isnt depreciated?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Xrm.Utility is throwing an error

    The JS Webresource is being used on a form event - OnLoad

    The function is basically

    MyFunction(ExecutionContext) {

    Var myVariable = Xrm.Utility.getGlobalContext();

    }

    It errors out just saying Xrm.Utility is not recognized.

    I've been following this

    itsfascinating.com/.../

    sachinbansal.blog/.../

    I was able to get most functions to work by using the ExecutionContext.getFormContext.context rather than the Xrm.Utility.getGlobalContext() but it still stumps me why the Xrm.Utility. is not working.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Xrm.Utility is throwing an error

    Hello,

    Can you please include the code that demonstrates how you use Xrm.Utility? Also can you please provide the description on where you use your JS webresource? Is it form script or ribbon or custom html/js webresource?

  • Lucas H Profile Picture
    Lucas H 279 on at
    RE: Xrm.Utility is throwing an error

    Maybe this page will help: GetGlobalContext function and ClientGlobalContext.js.aspx in model-driven apps - Power Apps | Microsoft Docs

    Specifically: "You must include a reference to the ClientGlobalContext.js.aspx page located at the root of the web resources directory to be able to use the GetGlobalContext 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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans