Problems with using a Variable to take different paths

Hi, I’m trying to create a scenario in which I cycle through an array
if among the elements of the array I find one that has a specific value I want to do one thing
if none of the elements has that value I want to do another thing

don’t know if there is a better way to do this “IF - THEN - ELSE”
but I tried to do it by creating a Variable, updating the value if I find the element
and using filters based on that variable to take different paths

here I create the variable the first time

Screenshot 2023-05-21 alle 17.11.38

after that I use an iterator to cycle through an array
and then a router to do different things
in the first one it enters only if in one of the elements of the array there is one that has a specific value
if it enters here (so it has found what I’m looking for) it uses a Set Variable module to change the value of the same variable I created before
“Deal_Found” = “exist”

now…

if I test before changing the value of the variable I get this, and it’s right

Screenshot 2023-05-21 alle 17.16.13

and if I test after changing the value of that variable (also in the other branches of the router)
I get this, and it’s also right, confirming that the value of the variable it has been changed and is correct

Screenshot 2023-05-21 alle 17.16.22

so the Variable is set correctly and has the correct value depending on what happened

but here is the problem:
if I use that variable inside a filter, like this for example

I don’t know why, but it always has the initial value (=“none”)
like it never changed (even though it has and is now =“exist”)
here the results of the filter and the result of a GetVariable immediately after

Screenshot 2023-05-21 alle 17.23.49
Screenshot 2023-05-21 alle 17.22.32

as you can see for the filter the variable has value “none” (in black above the variable name)
but for the get variable the same variable has value “exist”
so what I’m thinking is that for some reason the filter function has a bug or it does not work correctly
cause it does not consider the updated value of a variable but only the original one
making it impossible to use filters based on a variable value

You need to use the Get Variable Module and then set a filter based on that. The reason you are having the issue is the variable mapping that you are using is for Module 119 which is Set Variable and the value that you have over there won’t change even if you do Set Variable in later node. So, to get updated variable you will need to use Get a Variable Module.

2 Likes

Mhmm… I understand now how it works… thanks
tested it with a get Variable right before and the filter set to that new module and it works :wink:

1 Like