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)

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

I have the same question (0)
  • Suggested answer
    ajyendra Profile Picture
    1,738 on at

    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

  • Naeem Khan  Profile Picture
    44 on at

    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 ?

  • Verified answer
    ajyendra Profile Picture
    1,738 on at

    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

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

       }

    }

  • ajyendra Profile Picture
    1,738 on at

    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

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

  • ajyendra Profile Picture
    1,738 on at

    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

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