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 CRM (Archived)

JavaScript to open up a lookup field record in the same window if it exists.

(0) ShareShare
ReportReport
Posted on by

Does anyone have an example JavaScript script, that on being called (will be doing this via a ribbon button) it can check if a lookup field on the form in not null, and then open the lookup record itself in the current screen? (to act like a divert)

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hello,

    Did you try to use Xrm.Utility.openEntityForm(name,id,parameters,windowOptions) in your js function which you can call from your ribbon button. You can set openInNewWindow to false to open record in the same window.

    refer: msdn.microsoft.com/.../jj602956.aspx

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Graeme,

    Here is the function you need to call , just replace lookup field name and the entity name here.

    function OpenLookupWindow() {
        if (Xrm.Page.getControl("lookupfieldName") != null && Xrm.Page.getControl("lookupfieldName").getAttribute().getValue() != null) {
            contactLookup = window.parent.Xrm.Page.getControl("lookupfieldName").getAttribute().getValue();
            lookupId = contactLookup[0].id;
            lookupName = contactLookup[0].name;
            var parameters = {};
           // parameters["attributename"] = "test"; //You can pass additional parameters if you want.
            var windowOptions = {
                openInNewWindow: false  // You can control the window 
            };  
            window.parent.Xrm.Utility.openEntityForm("EntityName", lookupId, parameters, windowOptions);   // Replace entity name here . If its not work try to remove "window.parent"  
    
        }
        else
        {
            alert("control not found");
        }
    }


  • Community Member Profile Picture
    on at

    This worked, thanks Goutam.

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans