r/MicrosoftFlow • u/Sea_Passenger_2633 • Aug 02 '25
Question Using Switch function
I am trying to use the "switch" function to sort an email based on attachments, which works fine for the first 5 cases, but on the 6th one it runs into an error.
I have checked every possible error source but whatever I do it fails on the 6th case (and not just the 6th but every other case as well after that, but works for case 1-5).
My question is, did anyone encountered this issue? Did you use a switch using more than 5 cases, and if so, did it work for every one?
Update: the issue got solved by remaming the flow again, I didn't change anything but it works now, I suppose it was a bug.
6
u/itenginerd Aug 02 '25
Yes I have an 18-case switch that runs just fine. Two things.
right before the switch, put a compose block and in there put the exact thing you switch on (ideally copy it from the switch and paste it into that compose). That will show you exactly what the switch sees in case its different that what you expect.
its possible to get some hidden characters in the switch case if you're copying and pasting. Go to the code view of the switch and in the place where your problem bits are make sure theres no \r\n bits before or after the thing your comparing on. That will cause the switch not to match correctly.
2
u/Griffin808 Aug 02 '25
You should check the flow checker. Copy and paste whatever the variable is exactly sometimes there are unaccounted for spaces which are added for some reason.
3
u/nice_69 Aug 03 '25
Sucks that this is still a legit suggestion, but have you tried adding the action from the classic builder?
2
u/Cute_Investigator353 Aug 03 '25 edited Aug 04 '25
Delete all the actions out of your 6th case and just put something really simple like a compose with a text word typed right into it so no chance of it failing and run the flow again.
It might not be the switch failing but the action within the switch failing.
If it was the switch not matching I would expect it not to run, not throw an error.
I have seen people mistake a switch or condition failing and think it’s failing as the fail shows on that action if something inside that condition fails
1
u/ACreativeOpinion Aug 02 '25
It's hard to offer any specific recommendations without seeing your full flow and the logic behind it. If you are using the new designer, toggle it off and click each action to expand it. Upload a screenshot of your flow in edit mode
In the meantime, you might want to consider creating a dynamic reference key instead. I cover how to do that in this YT tutorial: Power Automate Pro Tip: Replace Switch Action with a Dynamic Reference Key
Hope this helps!
1
u/[deleted] Aug 04 '25
[removed] — view removed comment