Forum Discussion
Use dynamic content within If statement in expression in PowerAutomate
I am using Power Automate to save emails and attachments into a SharePoint Document Library. This is working well, and I now want to automatically apply metadata to the items that are uploaded.
I want to check the Subject field of an email I receive and if it contains a keyword, apply that keyword to the sharepoint column metadata.
I have more than 8 options so I can't use nested conditions (however using conditions DOES work). I am looking to use a switch case with nested if statements, but I am not sure how to refer to the "Subject" field inside an if statement.
For example, in the "On" field in a switch condition: (screenshot below)
if(contains(variables('Subject'),'jeff'),'1',if(contains(variables('Subject'),'josh'),'2',
Is not accepted by the expression field.
Any idea what I'm doing wrong?
- Someone on reddit suggested I turn on the experimental features for powerapps, which allows you to select dynamic content within expressions which answers my question. Thanks!
- jhumphriesCopper Contributor
I realised I had syntax problems with my expression. I have now got this line accepted:
if(or(contains(variables('Subject'),'keyword1','1'),variables('Subject'),'keyword2','2'))
However now when I try to save I see this error message:
"Flow save failed with code 'InvalidVariableOperation' and message 'The inputs of workflow run action 'Switch' of type 'Switch' are not valid. The variable 'Subject' must be initialized before it can be used inside action 'Switch'.'."
So many question remains...can I use the dynamic content "Subject" from a "when an email arrives" block in an if expression?
- RobElliottSilver ContributorHave you initialized the 'Subject' variable and set its initial value?
- jhumphriesCopper ContributorSomeone on reddit suggested I turn on the experimental features for powerapps, which allows you to select dynamic content within expressions which answers my question. Thanks!