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

Announcements

News and Announcements icon
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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans