Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Open a lookup field in new window

Posted on by Microsoft Employee

Hi Experts,

i have a requirement to open the lookup value in new window.

Requirements : Must be supported.

*This post is locked for comments

  • SEMAJ Profile Picture
    SEMAJ 10 on at
    RE: Open a lookup field in new window

    Do you know if there is a way to add the onclick functionality to the actual field rather than a ribbon button?

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: Open a lookup field in new window

    Hi,

    I share you my code. Copy and paste it to your JS file.

    function SetHyperlink()

    {

       var currentControl = Xrm.Page.ui.getCurrentControl();

      if (currentControl == null)

      {

          alert("No controls currently have focus.");

      }

    else

    {

     if (currentControl.getControlType() == "lookup")

     {

         var controlname = currentControl.getName();

         var controlvalue = new Array();

         var EntityType ="";

     var id= "";

     controlvalue = Xrm.Page.getAttribute(controlname).getValue();

       if(controlvalue !=null)

    {

        EntityType = controlvalue[0].entityType;

        id         = controlvalue[0].id;

       var windowOptions = {openInNewWindow: true};

           Xrm.Utility.openEntityForm(EntityType,id,null,windowOptions);

    }

    else

    {

     alert("Lookup field does not contain value, Please provide a value");

    }

      }

     }

     }

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: Open a lookup field in new window

    Hi

    first learn how to create a button and associate to a JS inside a form.

    [View:http://himbap.com/blog/?p=1473:750:50]

    Next, learn how to get lookup id and entity name

    [View:https://arunpotti.wordpress.com/2014/12/19/get-lookup-id-text-entityname-in-crm-using-javascript/:750:50]

    After that, learn how to get field type

    [View:https://msdn.microsoft.com/en-us/library/gg334266.aspx#:750:50]

    finally, learn how to open record

    [View:https://msdn.microsoft.com/en-us/library/jj602956.aspx#BKMK_OpenEntityForm:750:50]

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans