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!