Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Uncaught ReferenceError: XRM is not defined

(0) ShareShare
ReportReport
Posted on by 345

I have an entity form

I added a jscript file as a web resource

I am able to add css files to head of the document and other stuff using the javascript

But when I try using XRM, it throws 

VM11662:1 Uncaught ReferenceError: XRM is not defined

function load_css_file(filename){
var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
document.getElementsByTagName("head")[0].appendChild(fileref)
}
function onFormLoad(){
load_css_file('/WebResources/new_Style.css');
var something =  Xrm.Page.ui.tabs.get("sometabname").sections.get("some name");
};



*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Uncaught ReferenceError: XRM is not defined

    Thanks Pham Hong Nghiep

  • Suggested answer
    nghieppham Profile Picture
    nghieppham 4,755 on at
    RE: Uncaught ReferenceError: XRM is not defined

    Hi Vicky,

    To use xRM in HTML web resource. There are 2 ways to use it.

    1. If your HTML web resource host in CRM form, you can try by this way

    window.parent.Xrm.Page.ui.tabs.get("sometabname").sections.get("some name"); or you can pass context as first parameter when you add HTML web resource to your form. 

    2. You have to add the GlobalContext to your HTML web resouce like below code:

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

    You can follow this link for more information, msdn.microsoft.com/.../gg328541.aspx

    Regards,

    Nghiep Pham

    Please tick verify if it is useful for you.

  • svignesh Profile Picture
    svignesh 345 on at
    RE: Uncaught ReferenceError: XRM is not defined

    Hello Jason,

    I was using Chrome.

    Regards,

    Vicky

  • Jason M. Cosman Profile Picture
    Jason M. Cosman 5,234 on at
    RE: Uncaught ReferenceError: XRM is not defined

    Very strange; I wonder if it was cached somehow. I'm very glad it worked out and you were able to resolve this issue! May I ask what browser you were using?

  • svignesh Profile Picture
    svignesh 345 on at
    RE: Uncaught ReferenceError: XRM is not defined

    Hello Jason,

    it was a javascript file. And without making any changes it suddenly started working!

    regards,

    Vicky

  • Jason M. Cosman Profile Picture
    Jason M. Cosman 5,234 on at
    RE: Uncaught ReferenceError: XRM is not defined

    Good morning Vicky;

    I think what Andrii was trying to get to was; is this code stored in a javascript file? Or is it in a HTML Web Resource and inside of that HTML page you have this javascript? Usually the HTML file would be visible on the form through a Iframe etc. If you could answer this it would go along way to finding a resolution for you!

  • svignesh Profile Picture
    svignesh 345 on at
    RE: Uncaught ReferenceError: XRM is not defined

    Hello Andrii,

    I am using this inside the crm entity form

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Uncaught ReferenceError: XRM is not defined

    Hello,

    Where do you use this code? Is it inside CRM form or inside Html webresource?

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans