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:

No | Parameter | Description | Required |
1 | allowMultiSelect | The boolean value (true/false) that will let user to select multiple/single record(s). | No |
2 | defaultEntityType | Default entity type (logical name) when dialog show-up for the first time. | No |
3 | defaultViewId | Default view id when dialog show-up for the first time (related to parameter #2). | No |
4 | disableMru | Boolean value to enable/disable recent records. | No |
5 | entityTypes | An array of entity logical name that will be shown in the dialog. | Yes |
6 | filters | An array of the object (filterXml + entityLogicalName) for default filtering each of the record types. | No |
7 | searchText | Default string for searching | No |
8 | showBarcodeScanner | Indicates whether the lookup control should show the barcode scanner in mobile clients. | No |
9 | viewIds | An array of string guid for the enabled views. | No |
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:

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

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?
One thought on “Exploration: Dynamics CRM Client Scripting – Xrm.Utility.lookupObjects”