Flow: How do I use List Collector (not when sent from Catalog variable) in custom Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 12:32 PM - edited 07-28-2023 12:35 PM
I'm trying to build a List Collector activity so we can get some useful information out of them as arrays.
What I have built works fine if I dump an actual String into it (via Testing), but if I try to feed it a List Collector data pill from a record (NOT a Catalog variable) the input comes across as references to records, instead of just the string(s). My input is set to 'String' right now, though that seems to have very little impact on this working or not.
Here's my script. I was using var sciptArray = input.in_list_collector.toString().split(',') which didn't work either.
(function execute(inputs, outputs) {
var scriptArray = JSON.stringify(inputs.in_list_collector);
outputs.full_array = scriptArray;
var scriptArrayLength = scriptArray.length;
outputs.total = scriptArrayLength;
var uniqueArray = new ArrayUtil().unique(scriptArray);
outputs.unique = uniqueArray;
var uniqueArrayLength = uniqueArray.length;
outputs.unique_count = uniqueArrayLength;
for (i = 0; i < scriptArrayLength; i++) {
outputs.first = scriptArray[0];
outputs.last = scriptArray[scriptArrayLength-1];
}
for (j = 0; j < uniqueArrayLength; j++) {
outputs.unique_first = uniqueArray[0];
outputs.unique_last = uniqueArray[uniqueArrayLength-1];
}
})(inputs, outputs);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 12:56 PM
Well I hate answering my own post but in case someone else runs into this, this was the answer: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0831321
Script:
var scriptArray = [];
var gr = inputs.in_list_collector;
while(gr.next()) {
scriptArray.push(gr.getValue('sys_id'))
}