Reading Time: 3 minutes

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:

Diagram of a Power Automate flow, showing course codes being used in a Switch statement to choose between subsequent actions

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.

Two road signs pointing to the same location in opposite directions

Confusing road sign at Elan Village
cc-by-sa/2.0© Chris Henleygeograph.org.uk/p/265977


Testing and Debugging

I decided to test the flow using a simpler If conditional action:
Screenshot of a Power Automate flow showing an if conditional action based on matching the course code.

Looking at the initialisation of the variable in the run history, it looked exactly the same there:
Screenshot of the flow showing the variable initialisation in the run history

But looking at the variable assigned in the ‘no’ column, I could see that there were double quotes around it there:
Screenshot showing variables assigned in the flow's run history

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:
Screenshot of the flow's run history, showing the string variable has been escaped with backslashes and extra double quotes

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:

Flow screenshot showing the use of replace to trim the string in the expressions panel of the dynamic content window.

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

(Photo: PxHere)

(cc-by-sa/2.0 - © Chris Henley - geograph.org.uk/p/265977)

Share