web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / The condition for sear...
Power Automate
Answered

The condition for searching for a word in the subject of an email in Power Automate flow does not work

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi! Please help me figure out how the condition works in Power Automate flow.

I use a connector: When a new email arrives in a shared mailbox, insert a row in Excel Online Business spreadsheet based on a specific condition else insert a row in other spreadsheet based on other condition.

 

Task: Check the subject of the received email for the presence of keywords, fulfill the If/then/else condition, depending on the result of the check.

 

Condition: Does the subject of the email contain the words "defective goods"? If yes, then write the line "defective goods" to the excel file, if not, check condition 2.

Condition 2 - does the subject of the email contain the word "size"? If yes, then write the line "size" to the excel file, if not, check condition 3.

Condition 3 - does the subject of the email contain the word "return"? If yes, write the line "return" to the excel file, if not, write the line "other" to the excel file.For some reason, in all cases, I have only the last condition on the path "no", i.e. the entry of the string "other". Emails arrive with different topics, but one condition is always met with the result of writing the line "other". What am I doing wrong?

 

I tried to put keywords in double quotes "" and removed the extra condition through AND - but it didn't help. 

 

It also confuses me that inside the Subject element of Dynamic content there is an expression 

 

triggerOutputs()?['body/subject']

 

Why are there words both body and subject?

 

The same thing is in the Split expression, which I use to capture individual words from the subject of the letter.
The scheme of conditions from Power Automate flow and other pictures in the attachment.
Connector.png
Conditions.jpeg
Split - expressionSplit - expressionSubject - Dynamic contentSubject - Dynamic content

Categories:
I have the same question (0)
  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    Could you please share more details about your scenario? Could you share some examples of all kinds of related subjects?

     

    Best regards,

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @v-jefferni , thank you for your involvement. If I understand you correctly, would you like to know what email subject are received at the entrance to the condition?

    Examples of email subject (without quotes):

    • «Feedback form;1467361548;26.08.2023;Problem with the product;Defective goods» — Condition >> If yes (figure Conditions.jpeg)
    • «Feedback form;1467361701;25.08.2023;Problem with the product;The style or size of the product does not fit» — Condition >> If no >> Condition 2 >>If yes (figure Conditions.jpeg)
    • «Feedback form; 1467435930;24.08.2023;Gift card return;» — Condition >> If no >> Condition 2 >> If no >> Condition 3 >> If yes (figure Conditions.jpeg)
    • «Feedback form; 1467358892;23.08.2023;Other question;» — Condition >> If no >> Condition 2 >> If no >> Condition 3 >> If no (figure Conditions.jpeg)

    For some reason unknown to me, the conditions are always met according to the last scenario. The script always executes the "no" branch even when the keywords are contained in the subject of the email.

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    If seems there are only two conditions within you scenario:

    1. 5 values

    2. 4 values

     

    However, whatever the subject is, you need the second, the third and the last value of the subjects populate into the table, so the Condition control is not needed at all. You can use only one Add a row into the table action, set below expressions for respective column:

    the second value, like 1467361548:

    split(triggerOutputs()?['body/subject'], ';')[1]

     

    the second value, like 26.08.2023:

    split(triggerOutputs()?['body/subject'], ';')[2]

     

    the last value, like Defective goods:

    last(split(triggerOutputs()?['body/subject'], ';'))

     

    Best regards,

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi@v-jefferni , 

    Thank you for your attempt. Your option looks suitable. I didn't know how to get the last value from Subject, so I came up with the idea of applying the condition.

    I did a test with your expressions. Unfortunately, the expression last(split(triggerOutputs()?['body/subject'], ';')) does not work for the topic "Feedback form; 1467358892;23.08.2023;Other question;". Your expression extracts an empty value instead of "Other question". Maybe it's because this Subject ends with a sign ; .

    I can't remove the ; sign because in the case of longer Subject like "Defective goods" it separates the last values.

    Do you have any thoughts on how this can be solved? I can't think of 😑

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    It doesn't matter. In this case you need to get the second last value from the array from split function.

    first(lastN(split(triggerOutputs()?['body/subject'], ';'),2))

     

    Best regards,

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @v-jefferni , 

    I'm sorry for taking up so much of your time. The expression you suggested helps to get the penultimate value in a separate cell. And I need to always get the last or penultimate value in one cell.

    I tried to do this through an If expression. But apparently I'm wrong in the syntax, my expression is not accepted. Perhaps this is due to the fact that I incorrectly denote an empty value in the first argument where the condition is checked.

    Please look at my example. What is my mistake?

    if(
    last(split(triggerOutputs()?['body/subject'], ';')) = null, 
    first(lastN(split(triggerOutputs()?['body/subject'], ';'),2)), 
    last(split(triggerOutputs()?['body/subject'], ';'))
     )

    In addition to the null value, I tried blank, empty, 0 and ' '.
    Or maybe there is another way to solve it?

  • Verified answer
    v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    In power automate, checking blank value can use the empty function:

    if(empty(last(split(triggerOutputs()?['body/subject'], ';'))), 
    first(lastN(split(triggerOutputs()?['body/subject'], ';'),2)), 
    last(split(triggerOutputs()?['body/subject'], ';'))
    )

     or leverage the equals function:

    if(equals(last(split(triggerOutputs()?['body/subject'], ';')),''), 
    first(lastN(split(triggerOutputs()?['body/subject'], ';'),2)), 
    last(split(triggerOutputs()?['body/subject'], ';'))
    )

     

    Best regards,

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @v-jefferni ,

    Hi , thanks for the last answer, it looked like a working one. I tested both options, but it turned out that after applying any of the options, no data is entered into excel at all if the Subject of the email is Feedback form; 1467358892; 08/23/2023;Other question; or Feedback form; 1467435930;24.08.2023;Gift card return;. It was as if the email hadn't arrived at all.

    When I added a space between single quotes in an expression with equal, the line in the excel file began to fill in, but the cell in which I was waiting for the value of Other question is still empty. I don't understand what's going on…

    It seems that the error is in the expression:

    first(lastN(split(triggerOutputs()?['body/subject'], ';'),2))

    I used it in a separate cell, with this expression, the string is not written to the excel file at all.

    As a result, I edited your expression as follows

    if(equals(last(split(triggerOutputs()?['body/subject'], ';')),''), split(triggerOutputs()?['body/subject'], ';')[3], last(split(triggerOutputs()?['body/subject'], ';')))

    this expression worked.

    Thank you very much for your help!

    P.S. I apologize for the long wait, for some reason I have to send replies to your messages several times, because my answers are not saved. I've been trying to send this reply for several times already.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 276 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 169

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard