Push values into array using Lookup records in Flow

Harish74
Tera Expert

Hi,

I'm trying to look up resource plan records and push all the Group managers of those resource plans into an array.

How is this possible in the flow designer?

2 REPLIES 2

ronprice
Giga Guru

Here is one way that you can do it using a Flow Action to contain the script.  You should also be able to do it by using a script to set a flow variable and looping through the fd_data object, but I haven't been able to get it to work that way yet.

Here's an excerpt from a flow

find_real_file.png

It creates a lookup records collection and then loops through it and calls the custom action to add the RP Manager sys_id to the array.  The array is represented as a comma-delimited Flow Variable string since Flow does not support arrays as a data type.

Then in the Set Flow Variable action, it sets the Flow Variable string to the output of the action:

find_real_file.png

The custom action simply has two inputs - a reference to User and an optional starting array string:

find_real_file.png

It then has a script step:

find_real_file.png

And a single output, which is set to the output of the script step:

find_real_file.png

Please mark as Helpful/Correct if this helped to resolve your issue.

 

Forgot to deduplicate the results.  Replace the script in the flow action with this:

(function execute(inputs, outputs) {
// ... code ...
  var arIDs = [];
  if (inputs.startingarray) {
    arIDs=inputs.startingarray.split(',');
    arIDs.push(inputs.rpmanager);
    var arrayUtil = new ArrayUtil();
    outputs.endingarray=arrayUtil.unique(arIDs).toString();
  }
  else {
    outputs.endingarray=inputs.rpmanager;
  }
})(inputs, outputs);