{"id":4153,"date":"2021-05-31T12:02:08","date_gmt":"2021-05-31T12:02:08","guid":{"rendered":"https:\/\/himbap.com\/blog\/?p=4153"},"modified":"2021-05-31T12:02:08","modified_gmt":"2021-05-31T12:02:08","slug":"easy-fix-for-it-is-of-type-null-but-is-expected-to-be-a-value-power-automate","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=4153","title":{"rendered":"Easy Fix for -&#8220;It is of type &#8216;Null&#8217; but is expected to be a value&#8230;&#8221;- Power Automate"},"content":{"rendered":"<p><strong>Problem<\/strong><br \/>\nWhile working with Switch control in Power Automate, if the field used in the switch control is blank we will get this error:-<\/p>\n<p><strong>&#8220;It is of type &#8216;Null&#8217; but is expected to be a value of type &#8216;String, Integer&#8221;<\/strong><\/p>\n<p>I am going to share one possible way of handling which I used, if you have a better way please feel free to share in comments.<\/p>\n<p><strong>Solution<\/strong><br \/>\nSometime when we are using Power Automate and we want to perform different action based on the option set value, using Swtich control can be easy to check different conditions compared to if condition. But your Flow will fail if your entity record does not contain value for that particular option set which means it is null.<\/p>\n<p>To avoid it we can use switch with the combination of if and simply set values based on the if results like below<\/p>\n<p>Let&#8217;s first take a variable which will hold value of the option set. Let&#8217;s say my flow will trigger on create of Account and I have created a variable which will hold value of the option set, by default I am setting it to null.<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4155 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk1-300x198.jpg\" alt=\"flowchk1\" width=\"300\" height=\"198\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk1-300x198.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk1-624x411.jpg 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk1.jpg 792w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now let&#8217;s add a if control and there we can put our express like below<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk2.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4156 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk2-300x79.jpg\" alt=\"flowchk2\" width=\"300\" height=\"79\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk2-300x79.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk2-624x163.jpg 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk2.jpg 894w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>In above screenshot I am using following express to check if option set contains some data or not<br \/>\n<strong>empty(triggerOutputs()?[&#8216;body\/new_butype@OData.Community.Display.V1.FormattedValue&#8217;])<\/strong><\/p>\n<p>If this is true, we can simply leave it as is because we have already assigned it as null and if it contains value we can use our Switch control and add case as required.<\/p>\n<p>Also keep in mind further while utilizing this variable which holds value for the option set, we need to use expression like following to set to Dynamics 365 option set field,<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk3.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4157 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk3-300x87.jpg\" alt=\"flowchk3\" width=\"300\" height=\"87\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk3-300x87.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk3-1024x296.jpg 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk3-624x180.jpg 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/05\/flowchk3.jpg 1097w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nI am using following expression<br \/>\n<strong>if(equals(variables(&#8216;BUType&#8217;),0),null,variables(&#8216;BUType&#8217;))<\/strong><\/p>\n<p><strong>Summary<\/strong><br \/>\nThis is how we can check if our option set field value is null or not and can check for the same while setting field value using Power Automate.<\/p>\n<p>Hope it will help someone!<br \/>\n<strong>Keep learning, Keep sharing !!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem While working with Switch control in Power Automate, if the field used in the switch control is blank we will get this error:- &#8220;It is of type &#8216;Null&#8217; but is expected to be a value of type &#8216;String, Integer&#8221; I am going to share one possible way of handling which I used, if you have a better way please&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=4153\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,402,522,593,891,728],"tags":[889,888,890,887,886],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4153"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4153"}],"version-history":[{"count":4,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4153\/revisions"}],"predecessor-version":[{"id":4160,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4153\/revisions\/4160"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}