Easy Fix for -“It is of type ‘Null’ but is expected to be a value…”- Power Automate

Problem
While working with Switch control in Power Automate, if the field used in the switch control is blank we will get this error:-

“It is of type ‘Null’ but is expected to be a value of type ‘String, Integer”

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.

Solution
Sometime 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.

To avoid it we can use switch with the combination of if and simply set values based on the if results like below

Let’s first take a variable which will hold value of the option set. Let’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.
flowchk1

Now let’s add a if control and there we can put our express like below
flowchk2

In above screenshot I am using following express to check if option set contains some data or not
empty(triggerOutputs()?[‘body/new_butype@OData.Community.Display.V1.FormattedValue’])

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.

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,
flowchk3
I am using following expression
if(equals(variables(‘BUType’),0),null,variables(‘BUType’))

Summary
This 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.

Hope it will help someone!
Keep learning, Keep sharing !!

Leave a Reply