cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate V
Advocate V

IF statement error due to evaluating expressions in both True and False options

As elaborated in the now-quiet https://powerusers.microsoft.com/t5/Building-Flows/MS-Flow-IF-statement-error-due-to-evaluating-both... forum post, we as Flow users are receiving error messages for IF statements in which a sub-expression in the TRUE option cannot be resolved, even when the condition does not evaluate to TRUE, or vice versa for FALSE.

Typically, an IF statement is available as a form of error handling when we know that one option should not be resolved, deliberately shaping the condition to guard against the unresolvable expression.

 

To reproduce the issue, consider this hypothetical expression, acted upon when a new SharePoint List item is created:

 

1    if(equals(substring(triggerBody()?['Email'],sub(Length(triggerBody()?['Email']),10),10), 'domain.com'),

2    substring(triggerBody()?['CompanyName'],1,2),

3    '<False option>')

 

If I know that the only entries for which 'CompanyName' from line 2 will be provided (and therefore parsable) will end in 'domain.com', this approach could (should is not of concern here) function as a way to prevent the flow from trying to perform a substring on the empty column. Currently, this instead results in the following error, when only lines 1 and 3 should be evaluated:

"InvalidTemplate. Unable to process template language expressions in action 'Send_me_a_mobile_notification' inputs at line '1' and column '2523': 'The template language function 'substring' expects its first parameter 'string' to be a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#substring for usage details.'."

The entire expression does not cause an error if line 2 is simply the "triggerBody()?['CompanyName']" reference instead of a substring expression.

 

In his forum post, Charles stated it well "Adding the conditional for each evaluation massively over complicates the flow[...]". Please confirm how this behaviour is viewed from the Flow development team's perspective, and whether we can expect it to be changed. 

 

Thanks,

Josh

3 REPLIES 3
Highlighted
Community Support
Community Support

Hi @joshnystrom,

 

Please take a try with expression below:

if(equals(substring(triggerBody()?['Email'],sub(Length(triggerBody()?['Email']),10),10), 'domain.com'),
if(empty(triggerBody()?['CompanyName']),'<False option>',substring(triggerBody()?['CompanyName'],1,2)),
'<False option>')

1    if(equals(substring(triggerBody()?['Email'],sub(Length(triggerBody()?['Email']),10),10), 'domain.com'),

2    if(empty(triggerBody()?['CompanyName']),'<False option>',substring(triggerBody()?['CompanyName'],1,2)),

3    '<False option>')

 

Best regards,

Alice

Highlighted

I also have the same issue. It is trying to evaluate the TRUE option when though it should not.

 

The execution of template action 'Create_HTML_table' failed. The column values could not be evaluated: 'The template language expression 'if(contains(body('Filter_array_Full_Update'),'System.NextStepETA'),item()['System.NextStepETA'],'NULL')' cannot be evaluated because property 'System.NextStepETA' doesn't exist, available properties are 'System.Id, System.WorkItemType, System.State, System.AssignedTo, System.Title, System.Tags'. Please see https://aka.ms/logicexpressions for usage details.'.

Highlighted
Advocate V
Advocate V

While testing @v-yuazh-msft's proposed solution (hesitantly, as I fundamentally disagree that such an approach should be necessary), I realized that a simpler workaround exists. Alice's suggestion works, just not for the reason you might expect. The reason is that by inverting the conditional logic on any IF expression, and moving the nested, potentially invalid expression to the FALSE option, one ensures that Flow does not unnecessarily attempt to evaluate it, seemingly just due to positioning within the expression.

 

So, for example, my hypothetical case is more easily corrected by making my condition IF(not(equals(X)),<desired FALSE>,<desired TRUE>. Simple, right?

 

1    if(not(equals(substring(triggerBody()?['Email'],sub(Length(triggerBody()?['Email']),10),10), 'domain.com')),

2    '<False option>',

3    substring(triggerBody()?['CompanyName'],1,2))

 

So, to the development team: If this is working as intended, please know that it negatively impacts our ability to write and interpret these expressions - everything must be done with the opposite conditional outcome in mind. And, one must stumble upon posts such as this to understand how to succeed at error-handling by expression.

 

To anyone else, if you can conceive of an IF expression where both the TRUE and FALSE options are potentially invalid expressions and it is redundant to wrap the TRUE option in another condition, please share it here as it would mean this workaround cannot always be employed. I haven't been able to dream up such a situation.

 

@hux Your expression should work if written as follows:

if(not(contains(body('Filter_array_Full_Update')),'NULL','System.NextStepETA'),item()['System.NextStepETA'])

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Users online (8,884)