How it is possible to change a variable inside a workflow^

Hello everyone, I have a workflow in which I have to set a FLAG outside a loop. I’m using a Define Variable to define the variable FLAG and set it to “no”. But in the Loop I have some logic, and based on this logic I want to change the value of the FLAG to “yes”. After the loop based on the value of the FLAG i want to perform some operation, but how I can change the value of FLAG ? I can use another Define Variable inside the loop to set FLAG to “yes” and THAN I can see that value outside the loop?

Hi Salvatore,

Per the workflow docs, a variable defined in an earlier step can be accessed by later steps:

“In general, when placing an inline variable, use JSONPath format: {{ $.stepName.variableName }} . Each inline variable requires two sets of curly braces, as well as the $ and the period immediately after it. The spaces on either side of the variable are optional. Each step’s technical name can be found in the workflow’s execution history.”

If that doesn’t help, do you have a screenshot from the workflow builder or a JSON excerpt of the workflow?

Hi @s_tartaglione,

The variables inside a loop cannot be accessed outside of it. Also, take a look at the loop operator description here. The loop items are run alongside any subsequent steps in the WF, so any additional steps after the loop operation is not expected to work.

Take a look at this thread too for more details.

ok thanks, there is a way to change the value of the variable that I have defined?

I don’t think you can change the value of a variable once you have defined it. You will probably need to create another variable that could be dependent on the first variable.

Again, if you want to do some calculation outside the loop based on the values inside the loop, it is not supported.

You cannot change the value of a variable. However, you can use Compare Operator to check a specific value and continue with one of the two branches based on response being true or false

ok , but i need to perform an action after the loop based on some things that happened in the loop