Exploration: Dynamics CRM Client Scripting – Xrm.Utility.lookupObjects

Do you know that in Xrm.Utility object now got a nice function called lookupObjects? When we called this function, it will help us open a nice dialog that lets us choose (single or multiple) records and return to us an array of the selected data. We can pass lots of combinations of parameters to make the dialog more focus on the business needs. 

This is the list of supported parameters that we can pass:

Lookup records dialog
NoParameterDescriptionRequired
1allowMultiSelectThe boolean value (true/false) that will let user to select multiple/single record(s).No
2defaultEntityTypeDefault entity type (logical name) when dialog show-up for the first time.No
3defaultViewIdDefault view id when dialog show-up for the first time (related to parameter #2).No
4disableMruBoolean value to enable/disable recent records.No
5entityTypesAn array of entity logical name that will be shown in the dialog.Yes
6filtersAn array of the object (filterXml + entityLogicalName) for default filtering each of the record types.No
7searchTextDefault string for searchingNo
8showBarcodeScanner
Indicates whether the lookup control should show the barcode scanner in mobile clients.
No
9viewIdsAn array of string guid for the enabled views.No
Supported parameters to invoke Xrm.Utility.lookupObjects

This is the sample of how we call the function:

var lookupOptions =
{
    defaultEntityType: "account",
    entityTypes: ["account", "salesorder", "new_customdocument"],
    allowMultiSelect: false,
    defaultViewId: "0D5D377B-5E7C-47B5-BAB1-A5CB8B4AC10",
    viewIds: ["0D5D377B-5E7C-47B5-BAB1-A5CB8B4AC10", "00000000-0000-0000-00AA-000010001003"],
    searchText: "Temmy",
    filters: [{ filterXml: "<filter type='or'><condition attribute='name' operator='like' value='A%' /></filter>", entityLogicalName: "account" }]
};
Xrm.Utility.lookupObjects(lookupOptions)
    .then(success => console.log(success), error => console.log(error));

Demonstration:

Demonstration how to invoke + return result

Here is the screenshot of the result after we click Add button:

An array of entity

Summary

If you ever needed a multi-entity lookup scenario that not required actual lookup (maybe just JSON text / 2 string attribute for logicalName and id). This API (Xrm.Utility.lookupObjects) will save you a lot of time and open a lot of capabilities ahead. I can think of making a PCF Component to show a single/set of records using this API behind it without the need of making complex data table relation behind it.

What do you think?

Advertisement

One thought on “Exploration: Dynamics CRM Client Scripting – Xrm.Utility.lookupObjects

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.