{"id":25134,"date":"2020-10-19T13:20:23","date_gmt":"2020-10-19T13:20:23","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=25134"},"modified":"2022-07-19T16:44:57","modified_gmt":"2022-07-19T11:14:57","slug":"how-to-set-or-map-null-value-in-lookup-field-using-power-automate-cds-connector-current-environment","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/10\/how-to-set-or-map-null-value-in-lookup-field-using-power-automate-cds-connector-current-environment\/","title":{"rendered":"How to set or map null value in Lookup Field using Power Automate CDS Connector (Current Environment)"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p style=\"text-align: justify;\">Power Automate is a powerful business application that allows the user to create and automate workflows across multiple applications and services without developers&#8217; help.<\/p>\n<p>In this blog, we will explore how to set a lookup field as null while mapping the Lookup field with another record\u2019s lookup field which has null value. We can simply handle this in custom programs (plugin, workflow, javascript, etc. ) but in Power Automate it is quite tricky if we use CDS(Current Environment) connector.<\/p>\n<p style=\"text-align: justify;\"><strong>Scenario<\/strong>: On Contact entity, there is a lookup field of <strong>Account<\/strong> entity named \u201cCompany Name\u201d and this \u201cCompany Name\u201d is null\/empty on the contact record. Now, we will create an opportunity record on the creation of the contact record and will map the \u201cCompany Name\u201d on the new Opportunity record. So, here we won\u2019t be able to create Opportunity record with direct mapping field of \u201cCompany Name\u201d since the \u201cCompany name\u201d is empty on the contact record. To handle this, we need to take some extra efforts, that is, we need to an add additional expression while mapping the field.<\/p>\n<p>We created a Power Automate which will get triggered on the creation of the Contacts entity record as shown below.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-1.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25137 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-1.png\" alt=\"set or map null value in Lookup Field using Power Automate CDS Connector\" width=\"627\" height=\"372\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-1.png 627w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-1-300x178.png 300w\" sizes=\"(max-width: 627px) 100vw, 627px\" \/><\/a><\/p>\n<ol style=\"text-align: justify;\">\n<li style=\"list-style-type: none;\">\n<ol style=\"text-align: justify;\">\n<li>We have added to Create Opportunity entity record as shown below using CDS(Current Environment)<br \/>\n<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-2.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25136 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-2.png\" alt=\"set or map null value in Lookup Field using Power Automate CDS Connector\" width=\"933\" height=\"484\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-2.png 933w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-2-300x156.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-2-768x398.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-2-660x342.png 660w\" sizes=\"(max-width: 933px) 100vw, 933px\" \/><\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol style=\"text-align: justify;\">\n<li style=\"list-style-type: none;\">\n<ol style=\"text-align: justify;\">\n<li>Then mapped all required fields and set Account lookup field.<br \/>\n<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-3-1.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25141 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-3-1.png\" alt=\"set or map null value in Lookup Field using Power Automate CDS Connector\" width=\"495\" height=\"257\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-3-1.png 495w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-3-1-300x156.png 300w\" sizes=\"(max-width: 495px) 100vw, 495px\" \/><\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol style=\"text-align: justify;\">\n<li style=\"list-style-type: none;\">\n<ol style=\"text-align: justify;\">\n<li>In the above screenshot, we have set lookup field with direct mapping without any additional expression, as &lt;EntitySetName&gt;(&lt;RecordGUID&gt;), e.g. accounts(&lt;accounted&gt;)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol style=\"text-align: justify;\">\n<li style=\"list-style-type: none;\">\n<ol style=\"text-align: justify;\">\n<li>In this case, Power Automate fails and you will get below error if Account lookup field does not contain data on the contact record:Error &#8211; The supplied reference link &#8212;- is invalid. Expecting a reference link of the form \/entityset(key).\n<p>To handle the above scenario, we need to add the below expression in the Account lookup field mapping as shown in the below screenshot. Here, we need to check the value conditionally using empty() function and set empty string &#8216; &#8216; to the lookup field.<\/p>\n<blockquote><p>if(empty(triggerOutputs()?[&#8216;body\/_parentcustomerid_value&#8217;]), &#8216; &#8216;,<br \/>\nconcat(&#8216;accounts(&#8216;, triggerOutputs()?[&#8216;body\/_parentcustomerid_value&#8217;],&#8217;)&#8217;))<\/p><\/blockquote>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol style=\"text-align: justify;\">\n<li style=\"list-style-type: none;\">\n<ol style=\"text-align: justify;\">\n<li>In the above expression, we are checking if Account lookup doesn\u2019t contain data (i.e. empty()) then set null, otherwise set value in the lookup field. For this, we need to concat \u201cEntitySetName\u201d and \u201cGuid\u201d of the record i.e. accounts(&lt;accountid&gt;)<br \/>\n<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-5.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25140 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-5.png\" alt=\"set or map null value in Lookup Field using Power Automate CDS Connector\" width=\"880\" height=\"409\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-5.png 880w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-5-300x139.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-5-768x357.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/set-or-map-null-value-in-Lookup-Field-using-Power-Automate-CDS-Connector-5-660x307.png 660w\" sizes=\"(max-width: 880px) 100vw, 880px\" \/><\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol style=\"text-align: justify;\">\n<li style=\"list-style-type: none;\">\n<ol style=\"text-align: justify;\">\n<li>\u00a0The above expression can be used to set the lookup field with null value in Create a new record action.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2>Conclusion<\/h2>\n<p style=\"text-align: justify;\">Using the above solution we can Set Lookup Field with null value using Power Automate CDS Connector (Current Environment).<\/p>\n<h2 style=\"text-align: left;\"><div class=\"su-heading su-heading-style-default su-heading-align-center\" id=\"\" style=\"font-size:15px;margin-bottom:5px\"><div class=\"su-heading-inner\">70% of global 2000 companies apply gamification to improve productivity and returns!<\/div><\/div><\/h2>\n<p><em><strong><a href=\"https:\/\/bit.ly\/3RD4lYW\" target=\"_blank\" rel=\"noopener noreferrer\">Gamifics365<\/a> <\/strong>\u2013 Spin the magic of games within Microsoft Dynamics 365 CRM to improve user adoption, enhance productivity, and achieve company goals!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Power Automate is a powerful business application that allows the user to create and automate workflows across multiple applications and services without developers&#8217; help. In this blog, we will explore how to set a lookup field as null while mapping the Lookup field with another record\u2019s lookup field which has null value. We can\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/10\/how-to-set-or-map-null-value-in-lookup-field-using-power-automate-cds-connector-current-environment\/\">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":[9,16,18,19,1985],"tags":[1955,262,263,2007,2082,1975,1989],"class_list":["post-25134","post","type-post","status-publish","format-standard","hentry","category-common-data-service","category-dynamics-365","category-dynamics-365-v9-2","category-dynamics-crm","category-power-automate","tag-cds","tag-cds-dynamics-365","tag-cds-dynamics-365-crm","tag-dynamics-365-power-automate","tag-lookup-field","tag-power-automate","tag-power-automate-flows"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/25134","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=25134"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/25134\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=25134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=25134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=25134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}