cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
444
Views
0
Helpful
3
Replies

Adding data to variable as part of for each loop

hoylandpaul
Level 1
Level 1

In workflows is it possible to add to a variable as part of a for each loop.

I want to check each networks security appliance for an inbound any any rule and then send an email with all the networks in it.

In python I would just add to a global list, is this possible in workflows?

thanks

 

3 Replies 3

@hoylandpaul Yes, you can use a Set Variable activity inside of a For Each loop to append data to a Local variable and then use that variable later in a Send Email activity. Note that to append data to a variable, you reference the same variable in the Variable to update field, and then again as the first variable in the New value field, followed by the new data (one or more additional variables). See the example below. Note that with this approach, you may have to normalize the string and remove a leading comma (,).

EdNovakCiscoWorkflowsTME_0-1771417976926.png

Another option is to use Table activities.  Here's an example where a For Each loop is checking multiple organizations for networks with a specific tag. If networks are found, the networks are read into a table, and then that network list is used in a nested For Each Loop to read each network ID into a new table that is used later to iterate over just the tagged networks from all Organizations.

EdNovakCiscoWorkflowsTME_1-1771418033502.png

 

 

Network Platform Team
Workflows - Technical Marketing Engineer

Thanks Ed,

I've tried to use the set variables method but I'm unable to use the variable to update in the new value field (see screenshot). any ideas?

 

 

Screenshot 2026-02-24 at 10.35.01.png

@hoylandpaul When a variable is not selectable in the Browse Variables window, it is because of a Data Type mismatch. 
I think you may be trying to assign a string to an array. There are some improvements planned for arrays, until then, the best way to do this is to use a string to collect all the sting values, and then use a Python activity to convert the string of strings into a proper array. Here's an example of a string where new string values are appended to it. Note that this does result in a leading comma, that is removed when the string is normalized into an array. If you need an example of that Python activity, let me know.

EdNovakCiscoWorkflowsTME_0-1771938534652.png

 

Network Platform Team
Workflows - Technical Marketing Engineer