Hello everyone and welcome to my blog. In today’s blog I will discuss on how we can workaround issues while using Switch Case in Power Automate flows.
If you want to understand how to check for null conditions in switch-case of Power Automate flow, you will find this blog useful.
Through my blog I share interesting tips and discuss on latest releases of Microsoft.NET technologies, Dynamics 365 and Power Platform, SharePoint and Client scripting libraries. Please subscribe to my blog to stay updated.
Let’s understand the problem statement. In the below illustration, I am retrieving the items from SharePoint list and then use a switch-case construct on the Sign-off status field.
A simple Power Automate flow with a harmless switch-case construct. I execute the flow. And guess what, I get the below error which honestly was pretty surprising for me. I was not expecting this.
The execution of template action 'Switch' failed: The result of the evaluation of 'scope' action expression '@items('Apply_to_each')?['Sign_x002d_off_x0020_status']' is not valid. It is of type 'Null' but is expected to be a value of type 'String, Integer'.
What is the cause of this error? If you observe the error message carefully it’s pretty easy to guess. Turns out the switch-case construct in Power Automate can only have string and integer values in condition expression.
Inside a switch-case, if the condition expression evaluate to null, the switch-case construct won’t be able to handle null value and will throw this error.
So what’s the workaround? As a workaround, we need to perform a null check for the condition before using it in switch-case. Below illustration show the modified flow.
Now when I execute the Power Automate flow, it worked fine.
Hope this helped. For similar interesting topics on Microsoft.NET and Power platform, you can subscribe to my blog.
Debajit Dutta
Business Solutions MVP
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.