I have a Flow where I am trying to parse a string that is created from a float. The float is converted to a string and then Substring is used to check if the first character is a minus symbol or not (so is is negative or positive?)
This is handles by an If statement, and the True and False conditions each contain a Substring. If there is a negative float supplied, the resultant string will be longer due to the minus symbol and the substring character length is adjusted.
The problem is this length is out of scope for a positive float. This shouldn't be an issue as positive floats won't trigger the branch of the If statement that contains the substring that will fail, but the entire function is failing.
It's as if Flow is evaluating each branch of the If statement and not the pertinent ones. If this was any other language this logic wouldn't be an issue - this is why If statements exist!
Solved! Go to Solution.
if expression evaluates everything at run time and hence it fails
y not add a condition branch for if
Regards,
Reza Dorrani
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @ChrisBenJohnson rather than hardcoding the length of the string, you could make it dynamic so that no matter how long the string is it will still figure out the correct length. I have only created a basic example, but it looks like this
I have a variable (float), called MyVar, which contains -50000
I have a second variable (string) which is going to be the everything from character 1 (5) to the end (the final 0) and uses the expression:
substring(string(variables('MyVar')),1,sub(length(string(variables('MyVar'))),1))
I should say I worked around this in my Flow by concatenating a few extra zeroes on the end of the string after converting the float. There will always be chopped off but it prevents the 'out of scope' errors when using substring.
Can you post screenshot of your Flow run highlighting the if condition checks etc.
Hi @RezaDorrani
I have a simple example where I was able to replicate the issue:
The expression in the final step is below:
if(
equals(
substring(
string(mul(sub(div(variables('TW'), variables('LW')), 1), 100)),
0,
1
),
'-'
),
substring(
string(mul(sub(div(variables('TW'), variables('LW')), 1), 100)),
1,
3
),
substring(
string(mul(sub(div(variables('TW'), variables('LW')), 1), 100)),
0,
3
)
)
The calculation should run as follows:
In the 'True' branch of the expression, substring will fail due to position (1, 3) requiring at least 4 characters in the supplied string. However the 'False' branch should be the one triggering, but the error I get back references (1, 3) from the True substring.
if expression evaluates everything at run time and hence it fails
y not add a condition branch for if
Regards,
Reza Dorrani
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @ChrisBenJohnson rather than hardcoding the length of the string, you could make it dynamic so that no matter how long the string is it will still figure out the correct length. I have only created a basic example, but it looks like this
I have a variable (float), called MyVar, which contains -50000
I have a second variable (string) which is going to be the everything from character 1 (5) to the end (the final 0) and uses the expression:
substring(string(variables('MyVar')),1,sub(length(string(variables('MyVar'))),1))
Thanks, this looks good, I am used to more forgiving langauges where substrings won't fail if too many characters are specified. It's sometimes really annoying that Flow won't just ignore the out of scope characters and just return what it has, but I guess that could lead to unexpected results in some situations.
Thanks, I am just scratching the surface of these quirks! I had previously used conditions but in a large Flow expressions save screen space and can be more quickly copied and pasted.
This does seem weird behaviour for an If statement though, wouldnt you say?
Yes it is weird
But I did not notice that the expression syntax does evaluate all the conditions in the expression
In this case the If condition branch helps to create the Yes,No branches
User | Count |
---|---|
27 | |
16 | |
15 | |
12 | |
11 |
User | Count |
---|---|
43 | |
30 | |
28 | |
23 | |
23 |