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 / MS Flow IF statement e...
Power Automate
Unanswered

MS Flow IF statement error due to evaluating both True and False options

(3) ShareShare
ReportReport
Posted on by

Hi,

 

I am building an expression in Flow to parse text in an MS Planner description to pick up values between tags.

 

For example Planner doesn't have a Level of Effort field, so I am putting tags in the description <LOE>12<LOE>, and trying to extract the value of 12 from the descripton. I will reuse the same logic to add any other needed attributes.

 

My problem is MS Flow seems to evalute both the True and False condition when I use an if statement to check if a tag is present (not all Planner tasks will have all/the same tags). If the tag is present, there will be a 3 element array, if not just return 0.

 

 

if(
 greater(length(split(body('Get_task_details')?['description'], '<LOE>')), 1),
 split(body('Get_task_details')?['description'], '<LOE>')[1],
 0
)

 

When no tag is present, I get the error:

 

InvalidTemplate. Unable to process template language expressions in action 'Set_variable' inputs at line '1' and column '2527': 'The template language expression 'if(greater(length(split(body('Get_task_details')?['description'], '<LOE>')), 1), split(body('Get_task_details')?['description'], '<LOE>')[1], 0)' cannot be evaluated because array index '1' is outside bounds (0, 0) of array. 

 

But why is Flow trying to evaluate the TRUE part of the if clause when no <LOE> is present?

 

I tried an alternative approach using subtring and indexing:

 

if(
 and(equals(triggerBody()?['hasDescription'], true), greaterOrEquals(indexOf(body('Get_task_details')?['description'], '<LOE>'), 0)),
 substring(
 body('Get_task_details')?['description'], 
 add(5, indexOf(body('Get_task_details')?['description'], '<LOE>')),
 sub(lastIndexOf(body('Get_task_details')?['description'], '<LOE>'), add(5, indexOf(body('Get_task_details')?['description'], '<LOE>')))),
 0
) 

With the same error, "substring can't have a negative argument", from the -1 being returned when <LOE> not present.

 

Am I missing something?

 

The only way I have gotten this to run is with setting each part of the evalutation statement in parts first, and then adding a Conditional Flow step where if the <LOE> was found go down one path, and if not then use 0. Adding the conditional for each evaluation massively over complicates the flow and is not flexible if we need to add/remove tags in the future.

 

Any help on how to do this is much appreciated.

Thanks!

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

    Hi @Anonymous,

     

    Thanks for feedback. I can reproduce this error message on my side.

     

    I will help take further investigation on it and back to you once I got a solution on it.

     

    Best regards,

    Mabel Mao

  • joshnystrom Profile Picture
    262 on at

    Hi Yamao,

     

    Just wondering if there has been any progress on this issue. I've consistently encountered this behaviour and it's a serious problem. It runs contrary to all expectations for an IF statement as a logic check, and prevents us from being able to use it to avoid having to introduce unnecessary Conditions. Please let us know if we can expect this to be addressed.

     

    Thanks,

    Josh

  • hux Profile Picture
    on at

    I also have this issue and would like to know when this can be resolved.

  • hux Profile Picture
    on at

    @v-yuazh-msft@v-yamao-msftCan you please update on the status of this bug?

     

    Thanks,

    hux-msft

  • joshnystrom Profile Picture
    262 on at

    @Anonymous et all, I was dissatisifed with the silence on this thread, so I converted it to a bug report here:

     

    https://powerusers.microsoft.com/t5/I-Found-A-Bug/IF-statement-error-due-to-evaluating-expressions-in-both-True/m-p/172716#M3035

     

    It's not resolved so to speak, but a workaround exists. By inverting your conditional logic and placing your potentially invalid sub-expression last (as the FALSE option), it seems to ensure that MS Flow doesn't attempt to evaluate it unnecessarily. In your case it looks like:

    if(
     not(greater(length(split(body('Get_task_details')?['description'], '<LOE>')), 1)),
     0,
     split(body('Get_task_details')?['description'], '<LOE>')[1]
    )

     There's likely a briefer way to check the opposite of your conditional statement [like not(contains()) ] but this should work.

  • Community Power Platform Member Profile Picture
    on at

    That is odd, but the work-around seems to be ok.

     

    Changing:

    if(greater(length(items('Contact')?['EmailAddresses']),1),items('Contact')?['EmailAddresses'][1]?['Address'],'no 2nd email')

     

    to 

     

    if(not(greater(length(items('Contact')?['EmailAddresses']),1)),'no 2nd email',items('Contact')?['EmailAddresses'][1]?['Address'])
     
    Allows it to work. Not the prettiest thing ever.

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 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard