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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error in open contact entity in modal window with js code

(0) ShareShare
ReportReport
Posted on by 1,345

Hi All,

I am trying to open contact entity in modal window with js code but getting an error and entity is not loaded with attributes. Modal window opens with an error " An error has occurred . Try this action again. If the problem continues, check the Microsoft Dynamics CRM Community for solutions or contact your organization's Microsoft Dynamics CRM Administrator. Finally, you can contact Microsoft Support". Below code for refernce. Can someone pls help me in this to fix it. Thanks!

function openContact()

{
var Contactlookup = window.parent.Xrm.Page.getAttribute("from").getValue();
var regardinglookup = window.parent.Xrm.Page.getAttribute("regardingobjectid");
if (regardinglookup == null || regardinglookup == undefined) return;
var regardinglookupvalue = regardinglookup.getValue();

// pop the associated contact in a new window if present - else display error to user
if (regardinglookupvalue != null && regardinglookupvalue != undefined) {
var lookupid = regardinglookupvalue[0].id;
lookupid = lookupid.replace("{", "");
lookupid = lookupid.replace("}", "");

//var options = {
// openInNewWindow: true
//};
//window.parent.Xrm.Utility.openEntityForm("contact", lookupid, null, options)
var DialogOption = new window.parent.Xrm.DialogOptions;
DialogOption.width = 900;
DialogOption.height = 620;
window.parent.Xrm.Internal.openDialog(window.parent.Xrm.Page.context.getClientUrl() + "/main.aspx?etn=contact&newWindow=true&histKey=795118304&pagetype=entityrecord&id={" + lookupid + "}", DialogOption, null, null, CallbackFunction);
//window.parent.Xrm.Internal.openDialog("Web Resource path",DialogOption,null, null,CallbackFunction);
function CallbackFunction(returnValue) { }
}
}

Thanks

DK

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Bas van de Sande Profile Picture
    4,383 on at

    Hi DK,

    can you remove the histKey=795118304 from the url you are opening?

    that parameter is refering to a specific session which is not present anymore

    Bas

  • DH kumar CRM Profile Picture
    1,345 on at

    Hi Bas,

    Thanks for your reply!

    I tried removing histkey but no luck & unable to open url in model window and it's the same error for modal dialog.

    window.parent.Xrm.Internal.openDialog(window.parent.Xrm.Page.context.getClientUrl() + "/main.aspx?etn=contact&newWindow=true&pagetype=entityrecord&id={" + lookupid + "}", DialogOption, null, null, CallbackFunction);

    And to let you know that if i copy paste that url which i gets in alert that opens fine contact entity in the browser window(new tab). So there is no mistake in building url. The url is built correctly with id but not opened in modal window.

    Plz suggest & help!

    Thanks

    DK

  • Christoph Maeder Profile Picture
    195 on at

    hi DK

    can you enable tracing and then have a look on the trace file? you should get there more details about the error.

    christoph

  • Suggested answer
    Bas van de Sande Profile Picture
    4,383 on at

    Hi DK,

    If  I take a closer look at your code..   why are you doing: window.parent.Xrm.Internal.openDialog?  Why are you refering to window.parent?  are you inside a CRM context or are you working on an embedded webresource?

    I think it is way safer to do this:

    Xrm.Utility.openEntityForm("account","A85C0252-DF8B-E111-997C-00155D8A8410");

    you can read more about this on this blog:

    www.dynamicsmonster.com/.../CRM-2015-Javascript-Opening-an-Entity-Form-from-Javascript

    Bas

    Bas

  • Suggested answer
    Waqar Sohail Profile Picture
    on at

    use window.open or Xrm.Utility.openEntityForm(

    if you want to open it in other windows you should use window.open.

    var baseUrl =  Xrm.Page.context.getClientUrl();
    
    var randomnumber = 100000000 + Math.floor(Math.random() * 900000000);
    
    if (!endsWith(baseUrl, '/'))
         baseUrl += "/";
    
    var url = baseUrl + "main.aspx?etn=" + entityLogicalName + "&extraqs=&histKey=" + randomnumber + "&id={" + guid + "}&newWindow=true&pagetype=entityrecord";
    
    window.open(url, "", "status=0,resizable=1,width=1000px,height=800px");
  • DH kumar CRM Profile Picture
    1,345 on at

    Hi bas,

    I am using this window.parent.Xrm.Internal.openDialog to open contact entity in modal window being at phonecall form.

    If i simply give this Xrm.Internal.openDialog then i am getting error xrm undefined that'why i added window.parent. then undefined error goes off so this it is accepting this js code.

    I am inside crm context but my requirement is to open contact entity in modal window so that i should not make entry again on phone call form to fetch details again. As i will perform some validate action in contact modal window and then want to be on phonecall form.

    I have tried this way Xrm.Utility.openEntityForm("account","A85C0252-DF8B-E111-997C-00155D8A8410"); but my requirement didn't meet so wanted to open that in modal window.

    Plz suggest some ways to achieve that

  • DH kumar CRM Profile Picture
    1,345 on at

    Thanks waqar,

    that way i am able to open but my requirement is to open contact entity in modal window. is this possible. Pls help me and you can see the above description why i am trying to achieve being at phonecall form.

  • Suggested answer
    Bas van de Sande Profile Picture
    4,383 on at

    Hi DK

    you might try to replace the window.open() with window.openDialog()

    see description here:

    developer.mozilla.org/.../openDialog

    in the opendialog you can specify that the window has to be modal.

  • Suggested answer
    Waqar Sohail Profile Picture
    on at

    DH as my knowledge Xrm.Internal.openDialog is not use for entities but we can use it for webresource. so you have to use window.open as it is recommend in SDK. else may get fail.  

  • Christoph Maeder Profile Picture
    195 on at

    exactly. and by the way, using Xrm.Internal.openDialog seems not to be supported.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans