Azure Logic App - simple condition to check for empty string variable fails
Asked Answered
B

3

5

Solved

Issue was due to error in child action as Thomas pointed out, not the way I was checking the variable value.


I've got a variable that's been initialized earlier in the LA. Later on I'm trying to check if the variable is empty using a condition.

enter image description here

Here's the output from the run history:

enter image description here

enter image description here

It looks like the variable is an empty string at this point, however the condition fails without any helpful information.

enter image description here

I've also tried null or wrapping the variable in the empty command and comparing to true/false. All gave the same failure.

Belgium answered 4/5, 2018 at 0:22 Comment(6)
Can you try something like that :@length(if(equals(triggerOutputs()?['headers']?['SAS-Uri'], null), '', triggerOutputs()?['headers']?['SAS-Uri']))Sabian
@Sabian - tried it but no luck. Are the ?'s like null conditional operators in c#?Belgium
Yes the ? Is a null propagation operatorSabian
The error message said that another action failed. Have you check your workflow ? It sounds like a child action is failingSabian
Ah, that was the problem. I assumed it was the condition action causing the problem, but it was a child action. I need to pay better attention to the message. Thanks!Belgium
Good to here. you should edit your question or close it if it is not really relevant for the community.Sabian
I
6

You can use the length function in the expression. I've found it helpful to also coallesce the value to an empty string before checking length.

Inhabited answered 4/5, 2018 at 0:30 Comment(2)
Okay, here's what I've got now, but still getting the same error. This is a http trigger LA and I'm getting the value from the headers, btw. I've initialized the variable like so: coalesce(triggerOutputs()['headers']['SAS-Uri'], ''). Then in my condition I've got length(variables('SasUri')) with a greather than 0.Belgium
Problem here is if you get null in the string that it will get an error. So be careful.Alarice
L
1

For me placing an empty string between double quotes in a condition action to recognize the empty string works well. Be aware however that once you enter the empty string in the condition action and save your logic app, if you afterwards go back in the designer and reopen the condition action the empty string enclosed in double quotes ("") is not displayed anymore.

enter image description here

Laverne answered 8/4, 2021 at 14:18 Comment(1)
This worked well for me. One of the only times to use double quotes in PowerAutomate/Logic Apps.Leo
M
0

I have done this in 2 step process: Step 1: In compose connector If(equals(items('For_each')?['Email'],null), '',items('For_each')?['Email'])

Step 2: in Condition connector length(outputs('Email-EmptyOrNull')) is equal ZERO?

It works for me.

Matins answered 11/4, 2023 at 6:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.