Recently I’ve been working on a Power App for academic and teaching office staff to organise feedback on postgraduate dissertations. Microsoft recommend a maximum of 30 connectors per Power App, so I decided to pass the course codes to Power Automate, where a Switch
action could be used to choose which course’s SharePoint lists to read data from.
This is how I had set that up in Power Automate:
The Switch statement compares the course code passed in from Power Apps with text strings providing the code for each course. It should match one of them and then follow that course of action. But it didn’t. The two seemingly identical strings didn’t match, and the flow ran into the default (matching none) condition instead.
Testing and Debugging
I decided to test the flow using a simpler If
conditional action:
Looking at the initialisation of the variable in the run history, it looked exactly the same there:
But looking at the variable assigned in the ‘no’ column, I could see that there were double quotes around it there:
However, adding double quotes around the strings to compare the DPCODE variable with didn’t solve the problem. It still didn’t match.
I tried changing the test condition to 'contains'
instead of 'is equal to'
and it did match. Unfortunately 'contains'
isn’t available as a comparison in the Switch
action. But it did mean that there had to be something else I couldn’t see around the outside of the string.
The Cause
Eventually, I found the reason higher up in the run history, in the raw outputs from importing the variable in the Power Apps connector:
The Power Apps connector had escaped the string with backslashes and extra double quotes before it was assigned to initialize the variable.
That was why the contains
comparison worked, but trimming off an extra pair of double quotes made no difference.
The Solution
Trimming the variable before passing it in made no difference, so the solution was to use replace
to remove the backslashes and extra double quotes when initializing the variable:
This is the code I used in the Expressions panel:
replace(replace(triggerBody()['text'],'\"',''),'"','')
First it removes the set of backslashes and double quotes, and then it removes the remaining double quotes.
If this doesn’t solve your version of this problem, here are some other useful links on this topic:
Useful Links
- Strings comparison using condition action in Power Automate
- Power Automate Condition / String Comparison not working
- Comparison of two string doesn’t seem to work
- Problem with comparing strings
(Photo: PxHere)
(cc-by-sa/2.0 - © Chris Henley - geograph.org.uk/p/265977)
Leave a Reply