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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to use logical IF ...
Power Automate
Unanswered

How to use logical IF with string function in Microsoft flow?

(1) ShareShare
ReportReport
Posted on by 46

I built a flow to abstract a GUID from email body when new emails come in. The email body could contain:

3932FB4C-0DF5-11E8-A5C3-7804C4623542

or 

KeyStart***3932FB4C-0DF5-11E8-A5C3-7804C4623542***KeyEnd

 

I have built the following expression to extract the GUID

 

if(greater(indexof(body('Html_to_text'), '***KeyEnd'), 1),
substring(body('Html_to_text'), Add(indexof(body('Html_to_text'), 'KeyStart***'), 11), 36),
substring(body('Html_to_text'), 0, 36))

 

For the second case, it works. For the first case, it always returns "index out of range" in the substring. Does anyone know why?

Categories:
I have the same question (0)
  • v-xida-msft Profile Picture
    on at

    Hi @Gaolai,

     

    Could you please share a screenshot of your flow's configuration?

     

    The issue is confirmed on my side, I think this issue is related to the second parameter within your if() function. But when I add the following formula within a separated "Compose" action, the "Compose" action works well when the email body contains 3932FB4C-0DF5-11E8-A5C3-7804C4623542:

    substring(body('Html_to_text'),0,36)

    12.JPG

     13.JPG

     

    I afraid that this is issue is related to the if() function. In addition, you could consider take a try with the the following workaround as an alternative way:

    • Add a "When a new email arrives" trigger.
    • Add a "Html to text" action, Content field set to Body dynamic content of the trigger.
    • Add a Condition, click "Edit in advanced mode", type the following formula:
    @greater(indexof(body('Html_to_text'), '***KeyEnd'), 1)
    • Within "If/yes" branch of Condition, add a "Compose" action, Inputs set to following formula:
    substring(body('Html_to_text'),add(indexof(body('Html_to_text'),'KeyStart***'),11),36)
    • Within "If/no" branch of Condition, add a "Compose 2" action, Inputs set to following formula:
    substring(body('Html_to_text'),0,36)

    Image reference:14.JPG

    The flow works successfully as below:15.JPGBest regards,

    Kris

     

     

  • Gaolai Profile Picture
    46 on at

    Thanks for your reply. I actually found out where the problem came from, the If operation will evaluate both parameter 2 and 3 no matter if the parameter 1 is true or false.

  • StevenCollier Profile Picture
    20 on at

    Thanks @v-xida-msft this fixed my si,milar issue, but is there somewhere I can vote to get the if statement to not require this workaround. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard