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.
.
This is lookup dialog i wan to open on button click. Kindly help me.
*This post is locked for comments
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
yes. here is code where error is occurring Xrm.Utility.lookupObjects(lookupParameters).then(DisplaySelectedContact, null);
Hi,
Can you debug the code in console and Check which line it create issue. Is there any function/Properties named "LookObjects"?
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);
}
}
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
Use Above Code
Thanks
Ajyendra
If this answer is helpful.Please Mark as Verified.
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 ?
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.
- 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.
- 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 .
Hope this helps.
Thanks
Ajyendra
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6