On this Section we will see the How to Open the lookup dialog box using Javascript on Dynamics 365 instance.
Method and Syantx
Xrm.Utility.lookupObjects(lookupOptions).then(successCallback, cancelCallback)
Syntax : Xrm.Utility.lookupObjects(lookupOptions).then(successCallback, cancelCallback)
Example : Open a lookup dialog box
//Note :- Initialized the XRM boject first
var Xrm = parent.Xrm;
//Step 1- Create a Javascript function
function OpenLookupinJS () {
var lookupObjectParams = {};
lookupObjectParams.entityTypes = ["opportunity"];
lookupObjectParams.defaultEntityType = "opportunity";
lookupObjectParams.defaultViewId = "FD140AAF-4DF4-11DD-BD17-0019B9312238";
lookupObjectParams.allowMultiSelect = false;
Xrm.Utility.lookupObjects(lookupObjectParams).then(AssigneeSuccessCallback, AssigneeCancelCallback)
}
function AssigneeSuccessCallback(selectedItems) {
if (selectedItems != null && selectedItems.length > 0) {
var newAssignee = [{ id: selectedItems[0].id, typename: selectedItems[0].typename, name: selectedItems[0].name }];
//Assign the value to the specific html control
// To display the Lookup value Name on the HTML Text box
$("#TextBoxid").val(newAssignee[0].name);
// To display the Lookup value Name on the HTML Text box
// ID is required for internal use of the application i.e CRUD
$("#TextBoxid").val(newAssignee[0].id.substring(1, 37););
}
}
Comments
Post a Comment