Hi Learners,
Here is the supported / documented way of creating a custom Lookup input control using Client Side Scripting (JavaScript). We can use this to capture multiple records across multiple entities (Just like Party List control in Email Activities). It can be called from form events / HTML web resource to prompt input from users using Lookup control.
JavaScript Sample Code:

When invoked, this function prompts a lookup control as a model dialog (aligned to the right, like Quick Create Form)
Search will be performed across the entities specified in entityTypes property (Accounts, Leads and Contacts in this Sample)

We can select multiple records from the results

When we click on “Add“, the selected entity reference objects are passed to the Success Call back function as below. We can use this information further in our JavaScript Code based on the requirement.

lookupOptions object defines the look and behavior of the lookup control. It has got all the properties that an OOB lookup control on the form would have, like view selection control, disabling most recently used items etc.
Below is the list of properties available. More information available HERE
Property Name | Type | Required | Description |
allowMultiSelect | Boolean | No | Indicates whether the lookup allows more than one item to be selected. |
defaultEntityType | String | No | The default entity type to use. |
defaultViewId | String | No | The default view to use. |
disableMru | Boolean | No | Decides whether to display the most recently used(MRU) item. |
entityTypes | Array | Yes | The entity types to display. |
filters | Array of objects | No | Used to filter the results. Each object in the array contains the following attributes: |
searchText | String | No | Indicates the default search term for the lookup control. |
showBarcodeScanner | Boolean | No | Indicates whether the lookup control should show the barcode scanner in mobile clients. |
viewIds | Array | No | The views to be available in the view picker. Only system views are supported. |
References:
1) https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-utility/lookupobjects
Hi Sudheer, great post! Something I was reviewing myself but couldn’t get around it in time.
I believe this won’t work for all Lookups i.e. a lookup to a custom entity.
I think this works only for Regarding type? I could definitely be wrong here. Any thoughts?
LikeLiked by 1 person
Hi Priyesh, It works with all types of entities. But the catch here is, it’s a dynamically generated control used to “capture” the user input but not a control that “stores” the data in database.
LikeLiked by 1 person
Ah! Exactly what I had at back of my mind. I can’t wait to try it out myself. Thanks for putting this out. Much needed post!
LikeLiked by 1 person
Nice one buddy.
LikeLiked by 1 person
Thankyou
LikeLike
Reblogged this on Mehdi El Amri.
LikeLike
Hi,
Can’t wait to try this for myself. Thanks for sharing!
Mehdi,
LikeLiked by 1 person