Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Open lookup window on button click in CRM

(0) ShareShare
ReportReport
Posted on by 44

Hi, 

I have requirement to open lookup dialog when button on sub grid is clicked. I have added a button called " Add existing inquiries" on sub grid form of custom entity "Inquiries". When user click button, a lookup window should open where user can add existing inquiries to grid. Button is added using Ribbon workbench, but no idea how to open lookup dialog using JavaScript.

Test-.png

This is lookup dialog i wan to open on button click. Kindly help me.

*This post is locked for comments

  • ajyendra Profile Picture
    1,738 on at
    RE: Open lookup window on button click in CRM

    Hi Naeem Khan ,

    It works for me. I am using version 9.1.0.8428 online and also verified in Version 1710 (9.1.0.9021) online .

    Which version are you using?

    Thanks 

    Ajyendra

  • Naeem Khan  Profile Picture
    44 on at
    RE: Open lookup window on button click in CRM

    yes. here is code where error is occurring   Xrm.Utility.lookupObjects(lookupParameters).then(DisplaySelectedContact, null);

  • ajyendra Profile Picture
    1,738 on at
    RE: Open lookup window on button click in CRM

    Hi,

    Can you debug the code in console and Check which line it create issue. Is there any function/Properties named "LookObjects"?

  • Naeem Khan  Profile Picture
    44 on at
    RE: Open lookup window on button click in CRM

    Hi ajyendra!

    Code is not working. Its throwing error " Object does not support property or method 'LookObjects' "

    function showLookupDialog() {

       try {

           debugger;

           var lookupParameters = {};

           //specify the list of entity types to be displayed in lookup dialog

           lookupParameters.entityTypes = ["contact"];

           //Sepecify the default entityType need to be displayed

           lookupParameters.defaultEntityType = "contact";

           //Default view need to be displayed

           lookupParameters.defaultViewId = "{A2D479C5-53E3-4C69-ADDD-802327E67A0D}"; // you can put here the view

           //allow multiple selection or not

           lookupParameters.allowMultiSelect = false;

           //list multiple views available on lookup dialog

           // lookupParameters.viewIds = [“{0D5D377B-5E7C-47B5-BAB1-A5CB8B4AC105}”, “{A2D479C5-53E3-4C69-ADDD-802327E67A0D}”];

           Xrm.Utility.lookupObjects(lookupParameters).then(DisplaySelectedContact, null);

           } catch (e) {

           Xrm.Utility.alertDialog(e.message);

           }

           }

           function DisplaySelectedContact(selectedContact) {

           try {

           alert("Success");

           } catch (e) {

           Xrm.Utility.alertDialog(e.message);

       }

    }

  • Verified answer
    ajyendra Profile Picture
    1,738 on at
    RE: Open lookup window on button click in CRM

    As seen in image you provided . You can use Contact and

    how to get viewId of that "related inquires View". Steps to follow

    Open Advanced Find

    pastedimage1569239695576v1.png

    Use Above Code

    Thanks

    Ajyendra

    If this answer is helpful.Please Mark as Verified.

  • Naeem Khan  Profile Picture
    44 on at
    RE: Open lookup window on button click in CRM

    Thank you Ajyendra ! As mentioned I have two entity "Contact" and "Inquiries". Which entity lookup id should I use ? and my default entity will be contact ?

  • Suggested answer
    ajyendra Profile Picture
    1,738 on at
    RE: Open lookup window on button click in CRM

    Hi Naeem Khan ,

    One way to do it is

    function showContactLookupDialog() {

    try {

    var lookupParameters = {};

    //specify the list of entity types to be displayed in lookup dialog

    lookupParameters.entityTypes = [“contact”];

    //Sepecify the default entityType need to be displayed

    lookupParameters.defaultEntityType = “contact”;

    //Default view need to be displayed

    lookupParameters.defaultViewId = “{00000000-0000-0000-00AA-000010001004}”; // you can put here the view id you want to display you can get viewid from advanced Find

    //allow multiple selection or not

    lookupParameters.allowMultiSelect = false;

    //list multiple views available on lookup dialog

    // lookupParameters.viewIds = [“{0D5D377B-5E7C-47B5-BAB1-A5CB8B4AC105}”, “{A2D479C5-53E3-4C69-ADDD-802327E67A0D}”];

    Xrm.Utility.lookupObjects(lookupParameters).then(DisplaySelectedContact, null);

    } catch (e) {

    Xrm.Utility.alertDialog(e.message);

    }

    }

    function DisplaySelectedContact(selectedContact) {

    try {

    alert("Success");

    } catch (e) {

    Xrm.Utility.alertDialog(e.message);

    }

    - Open ribbon workbench , select the solution which you have created .

    - Now go to the area Form , Subgrid  , Home where you want to add your action , find the button.

    - If its existing button then right click on button --Customize Button if its new button then also you can find this options.

    pastedimage1569238241104v2.png

    - Now again right click on button just select - Customize Command. You can see the commands in command area highlighted in the above screenshot.

    - Select the command  and mapped web resource and your function.

    pastedimage1569238241104v2.png

    - Don't forget to map the command to your button command properties. When you select the button in the Ribbon Workbench you can see command .

    pastedimage1569238241106v3.png

    Hope this helps.

    Thanks

    Ajyendra

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 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…

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 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans