{"id":29105,"date":"2021-08-23T10:47:16","date_gmt":"2021-08-23T10:47:16","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=29105"},"modified":"2021-10-07T11:26:50","modified_gmt":"2021-10-07T05:56:50","slug":"multi-entity-table-lookup-in-dynamics-365-crm","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2021\/08\/multi-entity-table-lookup-in-dynamics-365-crm\/","title":{"rendered":"Multi-Entity\/Table lookup in Dynamics 365 CRM"},"content":{"rendered":"<h2 style=\"text-align: justify;\"><strong>Introduction:<\/strong><\/h2>\n<p style=\"text-align: justify;\">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.<\/p>\n<p style=\"text-align: justify;\">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.<\/p>\n<pre class=\"lang:css gutter:true start:1\">OrganizationRequest multiLookupOrgReq = null;\r\nOneToManyRelationshipMetadata accountMetedata = null;\r\nOneToManyRelationshipMetadata contactMetedata = null;\r\nOneToManyRelationshipMetadata leadMetedata = null;\r\nOrganizationResponse organizationResponse = null;\r\ntry\r\n{\r\n\/\/create request object\r\nmultiLookupOrgReq = new OrganizationRequest();\r\n\/\/ give lookup attribute information\r\nmultiLookupOrgReq.Parameters[\"Lookup\"] = new LookupAttributeMetadata()\r\n{\r\nSchemaName = \"ikl_Distributor\",\r\nDisplayName = new Label(\"Distributor\", 1033)\r\n};\r\n\/\/request name\r\nmultiLookupOrgReq.RequestName = \"CreatePolymorphicLookupAttribute\";\r\n\/\/Create relationship objects\r\naccountMetedata = new OneToManyRelationshipMetadata();\r\naccountMetedata.ReferencedEntity = \"account\";\r\naccountMetedata.ReferencingEntity = \"ikl_retailer\";\r\naccountMetedata.SchemaName = \"ikl_retailer_account\";\r\ncontactMetedata = new OneToManyRelationshipMetadata();\r\ncontactMetedata.ReferencedEntity = \"contact\";\r\ncontactMetedata.ReferencingEntity = \"ikl_retailer\";\r\ncontactMetedata.SchemaName = \"ikl_retailer_contact\";\r\nleadMetedata = new OneToManyRelationshipMetadata();\r\nleadMetedata.ReferencedEntity = \"lead\";\r\nleadMetedata.ReferencingEntity = \"ikl_retailer\";\r\nleadMetedata.SchemaName = \"ikl_retailer_lead\";\r\nmultiLookupOrgReq.Parameters[\"OneToManyRelationships\"] = new OneToManyRelationshipMetadata[]\r\n{\r\naccountMetedata,contactMetedata,leadMetedata\r\n};\r\n\/\/execute request\r\norganizationResponse = _service.Execute(multiLookupOrgReq);\r\n}\r\ncatch (Exception ex)\r\n{\r\nthrow new Exception(ex.Message);\r\n}\r\n<\/pre>\n<p>And now when we execute the above code it will create lookup field with four entities as shown in the below screenshot:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/image001-ink-19.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-29106\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/image001-ink-19.png\" alt=\"Multi-Entity\/Table lookup in Dynamics 365 CRM\" width=\"1132\" height=\"447\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/image001-ink-19.png 1132w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/image001-ink-19-300x118.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/image001-ink-19-768x303.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/image001-ink-19-1024x404.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/image001-ink-19-660x261.png 660w\" sizes=\"(max-width: 1132px) 100vw, 1132px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\"><strong>Conclusion:\u00a0 <\/strong>As illustrated above, by using multi-entity\/table feature you can easily set value in the lookup field instead of creating multiple lookup fields.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/user-adoption-monitor-in-dynamics-crm\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"wp-image-28863 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/UAM.jpg\" alt=\"User Adoption Module\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/UAM.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/UAM-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/UAM-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/08\/UAM-660x165.jpg 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2021\/08\/multi-entity-table-lookup-in-dynamics-365-crm\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2361],"tags":[2369],"class_list":["post-29105","post","type-post","status-publish","format-standard","hentry","category-technical","tag-lookup-field-dynamics-365"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/29105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=29105"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/29105\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=29105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=29105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=29105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}