Table of contents:
The problem: How to use the output of a switch action as dynamic content in Power Automate?
I assume that you are familiar with the switch functions in Power Automate and Power Apps.
The Switch function evaluates a formula and determines whether the result matches any value in a sequence that you specify. If a match is found, a corresponding value is returned.
This can be helpful in many situations when evaluating multiple cases.
But if we use a switch action how can we use the output of the arrived case (switch case) as dynamic value in sequence actions?
The following image shows that we have as dynamic value all outputs that could occur in the switch. However, we know that only one output will be filled and we want to use only this filled output.
In this example, we want to email only the Word content that actually has content.
The solution: Use the Power Automate coalesce expression
This problem can be solved with the coalesce expression.
According to Microsoft's definition, coalesce does the following:
"The Coalesce function evaluates its arguments in order and returns the first value that isn't blank or an empty string." (Source: Blank, Coalesce, IsBlank, and IsEmpty functions in Power Apps - Power Platform | Microsoft Learn)
I.e. we insert a Compose action with the following expression:
coalesce(DynamicSwitchOutput1, DynamicSwitchOutput2, DynamicSwitchOutput1)
You should replace the blue values with all possible switch outputs.
I.e. in this example I used the following expression.
coalesce(outputs('Populate_a_Microsoft_Word_template')?['body'],outputs('Populate_a_Microsoft_Word_template_2')?['body'],outputs('Populate_a_Microsoft_Word_template_3')?['body'])
This way you can use the output of the Compose Action afterwards, since it then contains the effective output of the Switch Action.
Do you like this article?
Please write a comment or leave a like below and follow me on LinkedIn.
If you have any questions, I'm happy to help.
Marc Sigrist (Powerfully GmbH, Switzerland)
Comments