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

  • Community Member Profile Picture
    on at
    RE: JavaScript to open up a lookup field record in the same window if it exists.

    This worked, thanks Goutam.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: JavaScript to open up a lookup field record in the same window if it exists.

    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");
        }
    }


  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: JavaScript to open up a lookup field record in the same window if it exists.

    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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans