Need to combine two list collector values in flow designer using custom action servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2024 10:31 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2024 11:23 PM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 01:06 AM
Hi Abhay,
Thanks for the Reply.
Can you please help me how to combine both values using flow variables.
Thanks,
Anusha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2024 03:10 AM
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.