Skip to main content

Notifications

Community site session details

Community site session details

Session Id : HvkxdeMRBOBSwrdB7mqyZa
Power Automate - Building Flows
Answered

Using Contains in a switch action to filter the subject of an email

Like (0) ShareShare
ReportReport
Posted on 8 Feb 2024 00:45:34 by 41

Hi,

 

I am trying to automate sending an email to different Org Codes within my organization based on the subject of the email coming in. For example if the Subject of the email contains Org code H45, I want it to send to the people from H45. If it contains B12, I want it to send to the people from B12 and so forth. There are about 30 Org codes so I don't think there is a way to use the Condition Action so I'm trying to use Switch and then use the function "contains" to find the organization code and trigger the email to the right place.

 

This is what I have for the contains function, but it's not working:

contains(triggerBody()?['Subject'], 'H45')
 
Is there a better way to do this? Or could someone help write the correct contains function?
Thank you! I am still very new to power automate.

 

 

acondie_0-1707352885452.png

 

  • Verified answer
    SanmeshG Profile Picture
    1,938 Super User 2025 Season 1 on 09 Feb 2024 at 06:10:14
    Re: Using Contains in a switch action to filter the subject of an email

    Hi @acondie  ,

     

    Looks like you are using Person/Group type of column.

     

    Initialize a variable of type string and inside apply to each append the email to that variable by adding the dynamic email content and add a ; after that. 

     

    Now move your send email action outside of the apply to each action and in Send To pass the variable that will have all email IDs.

     

    If this solves your problem , give this a thumbs up and mark this as a solution to close this thread.

     

    Thanks,

    Sanmesh

  • acondie Profile Picture
    41 on 09 Feb 2024 at 04:04:10
    Re: Using Contains in a switch action to filter the subject of an email

    Okay this seems to be working now-

     

    acondie_0-1707451430990.png

    The only issue now, is the email is sending three times? How do I stop that?

  • acondie Profile Picture
    41 on 09 Feb 2024 at 03:53:12
    Re: Using Contains in a switch action to filter the subject of an email

    Hi @SanmeshG ,

     

    I appreciate the help. I think I'm really close.

     

    I'm pulling the "Org" from the body of the email and then using that to go to the Sharepoint list and pull the contact emails (right now just using one person). That all seems to be fine when I test it and I get the correct outputs. However, when I go to send the email, I run into the issue where the email ends up being blank. The "subject" and "body" of the email keep changing to the Sharepoint image, even though I input them as outlook.

     

    Do you know what I could be doing wrong?

     

    acondie_2-1707450752785.png

     

     

    acondie_1-1707450711894.png

     

     

     

  • SanmeshG Profile Picture
    1,938 Super User 2025 Season 1 on 09 Feb 2024 at 03:36:52
    Re: Using Contains in a switch action to filter the subject of an email

    Hi @acondie  ,

     

    Here you might have extracted the Org Code from the email , pass that in the filter query 

     

    For ex : 

    OrgCode eq 'ABC'

     

    Here ABC is the Org Code and OrgCode is the internal column name of your column from that list , now you get the Emails that are mentioned for this or in the list , pass that in the To parameter(Remember here it depends again whether you have a multi-select people or Person column or a multi-line text column)

     

    If this helps , please give this a thumbs up and mark this as a solution.

     

    Thanks,

    Sanmesh

     

  • acondie Profile Picture
    41 on 08 Feb 2024 at 23:27:34
    Re: Using Contains in a switch action to filter the subject of an email

    Hi @SanmeshG ,

     

    I'm trying to build this out like you suggested, but I'm a little confused by what you mean when you say "email query", won't I still need to create a condition for each Org?

     

    acondie_0-1707434848342.png

     

  • acondie Profile Picture
    41 on 08 Feb 2024 at 23:06:23
    Re: Using Contains in a switch action to filter the subject of an email

    That's very smart! Thank you! I'll try that and get back to you if I have any questions.

  • SanmeshG Profile Picture
    1,938 Super User 2025 Season 1 on 08 Feb 2024 at 00:58:31
    Re: Using Contains in a switch action to filter the subject of an email

    Hi @acondie  ,

     

    Since you have mentioned you have about 30 Orgs , I would like to suggest an alternative approach , if you using switch that becomes a tedious/lengthy approach. So here's what I think you can do.

     

    Create a list in SharePoint , and store the Org codes and the associated people (here its not mentioned how many people are there for each org, I think there is a  limitation on how many people you can save in people picker column , so you can consider using a multiline text and add the email IDs separated by semicolon).

     

    Now once you find the Org Code from your email query the SP list using Get Items and send the email to the associated people.

     

    Hope this helps!

     

    Please give this a thumbs up and mark this as a solution if this answered your question.

     

    Thanks,

    Sanmesh

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,658 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard