In an iteration, I want to add lines to an array. When I’m done iterating, I want to process the array. But I can’t seem to add values to an array.
What is the problem?
At step 33, I create an array, then I enter an iteration at step 20. Within the iteration, I have a router, that will process contingencies, and, for each one, will add a line to the array (in this case simply adding a slack username based on whether it’s a bot [step 27], a user i’m seeing for the first time [step 30] , or a user i’ve seen before [step 28] ).
The problem I have is that I can’t seem to add to the array in any of these steps. I’m doing it using setVariable, which is meant to set the variable created in step 33, to a new array, which is the current value of the array in step 33 passed to the ‘add’ function. But it won’t work!
What have you tried so far?
If I reference the array as a plain text name (just typing FinalOutput, the variable I created at 33), I get an error that this isn’t a valid array. If I reference 33.FinalOutput, it runs, but the value of 33.FinalOutput never gets overwritten with the new array, I guess I’m just setting some new FinalOutput.
I have set the scope of the SetVariable modules to ‘one execution’, which I believe gets over the obvious potential scope problem.
couple of things.
Firstly module 33 is not producing any extra bundles so you don’t need that as the source of the aggregator. I assume module 33 defines the array and then module 20 is the one iterating over it and creating the extra bundles. So you can skip module 33 and define the array directly inside module 20. Either way, change the source module to that one.
Second - same thing for the array aggregator module. If you need a text, then replace the array aggregator with a text aggregator. If you need both, then you need an iterator first before the text aggregator, otherwise its not doing anything.
Now for the issue it self - you logic is flawed. There is no array on those routes that you can add these items to. Also the aggregator on the main route does not have access to those variables either. What you need is an aggregator after each of those set variable modules to give you an array, then another set variable module afterwards to store the array inside. Then on the main route place a get multiple variables module after the aggregation to retrieve said arrays and in the next module use merge() to create a new array with all the values.
Here is a mochup scenario to illustrate what I mean.
This is extremely helpful, thank you for the thorough response. I’ll go through your example and analysis in detail. AWESOME!!!
If I could impose, though, as I think this would help me a ton:
I’m confused about the scope of the variables in Make. I suspect that this is simply because my development experience is almost entirely in procedural languages, and I’m applying that reference frame here and it’s leading me to have an incorrect mental model - your detailed analysis will help to fix that, I have no doubt.
My mental model of the router is that it is like a switch statement. In some procedural languages, the scope of a variable is limited to the smallest encompassing scope. Given this, it makes sense to me that you say that variables set downstream of the router (i.e. inside a switch case) are limited to that branch.
But a bridge too far in your explanation, given my reference frame is: why would the variable declared upstream of the router not be in scope downstream? What causes it to go out of scope? The router? Why?
Genuinely, many thanks. I love these sorts of communities where people come together to genuinely help.
Yeah so the router is a splitter. Things live on their own branch after a router. So items in branch one will never be directly accessible in branch 2.
Variables declared inside a set variable module however are a bit weird. Once they are initially declared they exist inside the scenario it self independent of their position. But they are still not visible for mapping on other branches of a router. They are however accessible to the get variables module, and if a variable has been declared already, the get variables module will be able retrieve it’s current state at the time it executes.