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 the comments.
 

Solution


Sometimes when we are using Power Automate with Dynamics 365 CE and we want to perform different actions based on the option set value, using Switch control can be easy to check different conditions compared to if condition. But your Flow will fail if your entity record does not contain the value for that particular options set which means it is null.
 
To avoid it we can use the switch with the combination of if and simply set values based on the if results like below,
 
Let’s first take a variable that will hold the value of the options set. Let’s say my flow will trigger on create of Account and I have created a variable that will hold the value of the options set, by default I am setting it to null.
 
Easy Fix For -
 
Now let’s add an if control and there we can put our express like below,
 
Easy Fix For -
 
In the above screenshot, I am using the following expression to check if the option set contains some data or not,
  1. empty(triggerOutputs()?[‘body/[email protected]’])   
If this is true, we can simply leave it as is because we have already assigned it as null and if it contains the 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 expressions like the following to set to Dynamics 365 options set field.
 
Easy Fix For -
 
I am using following expression,
  1. 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 !!


Similar Articles
HIMBAP
We are expert in Microsoft Power Platform.