Push to array output variable in subflow

Bradley Koerner
Tera Contributor

In Flow designer, I have an output variable that is an array of objects. Within my subflow, I am iterating through a list of records and performing some operations (assembling data, calling a REST API, etc.) There are a handful of results for each given record, so I want to capture all of those results within my array.

My problem is that, while there is a Flow Logic to "Assign Subflow Outputs", it seems to only allow me to set my output array and/or its individual elements. For each of my records, I want to be able to push to the array. Is that possible?

Basically, I want Flow to be doing something like this: 

while (gr.next()) {
  var result = doThings();
  output.my_array.push(result);
}

But it only appears to let me do this:

while (gr.next()) {
  var result = doSomething();
  output.my_array = result
  // or
  output.my_array[0] = result;
}

It seems to me, only allowing setting of the array or hardcoded indexes completely defeats the purpose of an array.

13 REPLIES 13

OlaN
Giga Sage
Giga Sage

Hi,

Look at this video by @Göran WitchDoctor Lundqvist it should help you clarify how to work with complex objects as outputs from a Subflow.

That video deals with complex objects inside an action where the action's output is being set by script. That's not what I'm looking for.

I've created a simplified version of what I'm doing in my subflow here:

find_real_file.png

For each of my records, there are a couple different things that can happen. I want to know the result for each of those records. I want the output of the subflow to look something like this:

[
  {
    record: "INC123456",
    message: "Something happened"
  },
  {
    record: "INC123457",
    message: "Something else happened"
  }
]

But the way that Assign Subflow Outputs appears to work, I'll only get this output from the subflow:

[
  {
    number: "INC999999",
    message: "This is the last record that was iterated on"
  }
]

...because it's just resetting index 0 for each iteration. I want to be able to push to the output array for each iteration. 

Sorry for the spamming of my first reply.
When I posted, the replies disappeared.. but somehow got saved anyway.

Sadly I don't know if there is a way to push values to an output array the way you described.

The Assign subflow output action, does exactly that, it sets a value.

A workaround would be to build your output into a custom action, which returns an array.object, which you could use to assign the output from your subflow.

Hi,

Understood the situation by viewing the flow screenshots.

AFAIK, it's not possible. Subflow is used to return a reply so there's a need to move the loop to the main flow.

Setting output in a subflow within a loop will overwrite the previous output. That's the current specification.