In this article, we will learn to automatically change the lookup field’s target entity in Dynamics 365 CRM.
Why do we need to dynamically change the lookup’s target entity?
Consider a scenario where we are using a Customer Lookup field which have two entities namely Account and Contact. Now, we can easily filter the customer field to display the record for only one entity (Either Account or Contact) as per the business requirement with help of the below given solution.
Automatically changing the lookup’s target entity –
We will use the setEntityTypes client Web API to dynamically change the attribute’s target entity as shown below.
formContext.getControl(arg).setEntityTypes([entityLogicalNames]);Sets the types of tables allowed in the lookup control.
Validating the changes in Dynamics 365 –
- The customer lookup attribute’s target entity is automatically set to “Account” when an option-set field value is updated to “Account”.
- The customer lookup field’s target entity is automatically set to “Contact” when an option-set field value is updated to “Contact”.
Thus, we learned to automatically change the lookup field’s target entity in Dynamics 365 CRM.