Need to combine two list collector values in flow designer using custom action servicenow

anushadande1793
Tera Contributor

Hi

 

There are two list collector fields on the from (service catalog form) and we need to combine the values selected for those two list collector values in flow designer. I have written one custom script with the below code by taking inputs as list collector fields with the type 'string' and given a try with  output type as 'array-string/string' but still it is not working. Can someone helps on this please

 

var teamselected = inputs.teammember.toString();
 var teamselectedsplit =teamselected.split(',')
var scrumselected =inputs.scrummaster.toString();
 var scrumsplitedusers =scrumselected.split(',')
var au = new ArrayUtil();
 var finallist = GlideArrayUtil.union(teamselectedsplit,scrumsplitedusers);
 outputs.userssplitedafter =finallist.toString();
 
Thanks,
Anusha
3 REPLIES 3

Abhay Kumar1
Giga Sage

@anushadande1793 Create a flow variable and combine both value in set variable so you can use flow variable with having all value from both list collectors,hope this helps you.

Thanks

Hi Abhay,

Thanks for the Reply.

Can you please help me how to combine both values using flow variables.

 

Thanks,

Anusha

use this sample code with changing variables

// Initialize an empty array for the combined list

var combinedList = [];

 

// Add all elements from the first list collector, if present

combinedList = combinedList.concat(inputs.listCollector1 || []);

 

// Add only unique elements from the second list collector

(inputs.listCollector2 || []).forEach(function(item) {

    if (combinedList.indexOf(item) === -1) {

        combinedList.push(item);

    }

});

 

// Return the combined array to be assigned to the flow variable

combinedList;

Hope this will help.