Custom Lookup Control with multi select and with multiple entities

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 NameTypeRequiredDescription
allowMultiSelectBooleanNoIndicates whether the lookup allows more than one item to be selected.
defaultEntityTypeStringNoThe default entity type to use.
defaultViewIdStringNoThe default view to use.
disableMruBooleanNoDecides whether to display the most recently used(MRU) item.
entityTypesArrayYesThe entity types to display.
filtersArray of objectsNoUsed to filter the results. Each object in the array contains the following attributes:
searchTextStringNoIndicates the default search term for the lookup control.
showBarcodeScannerBooleanNoIndicates whether the lookup control should show the barcode scanner in mobile clients.
viewIdsArrayNoThe 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

Author: Sudheer Reddy Nelakurthi

Power Platform developer for 8 years

7 thoughts on “Custom Lookup Control with multi select and with multiple entities”

  1. 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?

    Liked by 1 person

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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s