Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

CRM HTML web resource cannot access Xrm.Page.data.entity.getEntityReference() without page refresh

Posted on by Microsoft Employee

I have an HTML web resource in CRM that is opened as an internal dialog (Xrm.Internal.openDialog).

I need to be able to get the parent entity's ID as well as several attributes for use in the dialog. During testing I noticed some unusual behavior that I have not been able to find a workaround for.

I can open the dialog from an Account and everything works as intended. If I then navigate to a different account and open the dialog I am unable to get the parent Account's ID and receive the following error. TypeError: Unable to get property 'entity' of undefined or null reference. If I press F5 and reload the page the dialog will work as intended and is able to get the parent Account's ID.

I am referencing ClientGlobalContext.js.aspx and creating my context when the page loads and then using the following code to get the parent Account entity reference.

this.Account = window.parent.frames[0].Xrm.Page.data.entity.getEntityReference();

How can I get this to work without the user having to reload the page each time they navigate to a different Account?

 

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM HTML web resource cannot access Xrm.Page.data.entity.getEntityReference() without page refresh

    Thank you for the reply. I may have to pass query string parameters to the dialog as I did in the past but I was hoping to be able to use Xrm to read them from the parent form since it is an internal dialog. I tried using window.parent.opener.Xrm as you suggested but it is null

    I am able to retrieve form data using the code below. The real question is, why does this work the first time I run it but then not work if I navigate to a different Account? It will work again if I F5 and refresh the new Account page. Why does it stop working when the user moves to a different Account? What is the refresh doing that causes it to work again?

    this.Account = parent.frames[0].Xrm.Page.data.entity.getEntityReference();
    this.OEM = parent.frames[0].Xrm.Page.getAttribute("new_oemdefault").getValue();
  • gdas Profile Picture
    gdas 50,085 on at
    RE: CRM HTML web resource cannot access Xrm.Page.data.entity.getEntityReference() without page refresh

    Hi ,

    Although Xrm.Internal has been deprecated so I would not suggest to use this , rather you can use openWebResource. For below D365 9.0 version use Xrm.Utility.

    docs.microsoft.com/.../openwebresource

    If you still want to use the unsupported method , you can pass query string parameter at the time of open the Dialog. Here is sample code  -

    function OpenDialogueWithHTML()
    {
    
        var webResourceURL =  "HTML Web Resource URL";
        var DialogOption = new Xrm.DialogOptions;
        DialogOption.width = 800;
        DialogOption.height = 620;
    
        //Passing parameters to webresource
        var addParams = "Param1=SomeText";
        webResourceURL = webResourceURL + "?Data=" + encodeURIComponent(addParams);
        Xrm.Internal.openDialog(webResourceURL, DialogOption, null, null, successCallback);
    }
    
    function successCallback()
    {
    
    }

     Try to access directly the control of parent field like below 

       window.parent.opener.Xrm.Page

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans