Please wait, loading...

 

Introduction:

Recently, Microsoft introduced the multi-entity/table lookup field which was one of the most awaited features. Previously it was only available for the OOB customer lookup field; for example, the customer field has contact and account for selection in the customer lookup field. In this release of Dynamics 365 CRM, it is now possible to create a lookup field that has a multi-entity/table. For example, for Retailer custom entity, we want to assign a Distributor and Distributor is lookup up field. Here, we want to assign Distributor to either Account, Contact or Lead entity. Earlier, in such cases we would have created three lookup fields with these entities and show/hide lookup field based on other options set field. But with recent release, it is now possible to create lookup field with multiple entities. So here we have created only one lookup field with Account, Contact and Lead entity. However, currently it can be done only programmatically but in the future it will be added to Microsoft UI.

Now, to create multi-entity/table lookup field we have written the below C# code. Here, we have created a Distributor lookup field with Account/Contact/Lead entities.

OrganizationRequest multiLookupOrgReq = null;
OneToManyRelationshipMetadata accountMetedata = null;
OneToManyRelationshipMetadata contactMetedata = null;
OneToManyRelationshipMetadata leadMetedata = null;
OrganizationResponse organizationResponse = null;

try
{
//create request object
multiLookupOrgReq = new OrganizationRequest();

// give lookup attribute information
multiLookupOrgReq.Parameters[“Lookup”] = new LookupAttributeMetadata()
{
SchemaName = “ikl_Distributor”,
DisplayName = new Label(“Distributor”, 1033)
};

//request name
multiLookupOrgReq.RequestName = “CreatePolymorphicLookupAttribute”;

//Create relationship objects
accountMetedata = new OneToManyRelationshipMetadata();
accountMetedata.ReferencedEntity = “account”;
accountMetedata.ReferencingEntity = “ikl_retailer”;
accountMetedata.SchemaName = “ikl_retailer_account”;

contactMetedata = new OneToManyRelationshipMetadata();
contactMetedata.ReferencedEntity = “contact”;
contactMetedata.ReferencingEntity = “ikl_retailer”;
contactMetedata.SchemaName = “ikl_retailer_contact”;

leadMetedata = new OneToManyRelationshipMetadata();
leadMetedata.ReferencedEntity = “lead”;
leadMetedata.ReferencingEntity = “ikl_retailer”;
leadMetedata.SchemaName = “ikl_retailer_lead”;

multiLookupOrgReq.Parameters[“OneToManyRelationships”] = new OneToManyRelationshipMetadata[]
{
accountMetedata,contactMetedata,leadMetedata
};

//execute request
organizationResponse = _service.Execute(multiLookupOrgReq);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

And now when we execute the above code it will create lookup field with four entities as shown in the below screenshot:

Multi-Entity/Table lookup in Dynamics 365 CRM

Conclusion:  As illustrated above, by using multi-entity/table feature you can easily set value in the lookup field instead of creating multiple lookup fields.

User Adoption Module

Please follow Source

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651&ssl=1
Microsoft Dynamics Community Profile

Learn more