- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:23 PM
I am trying to create a Custom Action in Flow Designer that will take the input of a List Collector, and output an Array of values from another field from the same table.
My Table has the following fields:
- group_name (display field)
- ad_group
So the select the values they want from the List Collector and my Custom Action is supposed to return an Array of the appropriate ad_group values from each selection.
Here are the Inputs in my Custom Action:
And then I have a Script step that has the following Input Variables:
And here is the Script:
(function execute(inputs, outputs) {
var gr1 = inputs.list_col;
var fld = inputs.fld_nm;
var ads = '';
//loop through records in list collector
gr1.query();
while(gr1.next()){
ads += gr1.getValue(fld) + ',';
}
//remove last comma from string
if(ads.slice(-1) === ','){
ads = ads.slice(0, -1);
}
//convert string to array
outputs.ad_array = ads.split(',');
})(inputs, outputs);
and here are the Output variables for the Script section:
Lastly, here are the Outputs of the Custom Action:
So, the weird thing is when I try to use this in my Flow, if I choose more than 1 selection in my List Collector, it works perfectly. But for some reason, if I only choose a single selection, it "doubles up" the value that it outputs.
Here is a log of one of these situations, where you can see a single value in the List Collector, but two values in my outputting array:
Does anyone have an idea why this is happening when I make a single entry into the List Collector, or have any idea on how to fix it?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 11:44 AM
After trying many of the recommendations and finding no success, I went back to my original code. I added a loop counter for the "while" loop and discovered that when I made a single selection, it was looping through twice. No idea why it is doing that, but that gave me an idea on how to fix it. I simply compared the value of the current iteration to the value of the previous one, and only included it if it was different. That seemed to finally work!
Here is the final code I ended up using. Thanks to all those who tried to help.
(function execute(inputs, outputs) {
var gr1 = inputs.list_col;
var fld = inputs.fld_nm;
var ads = '';
var curValue = '';
var prevValue = '';
//loop through records in list collector
gr1.query();
while(gr1.next()){
//get desired field value of current record
curValue = gr1.getValue(fld);
//check to see if value differs from previous value
if(curValue!=prevValue){
//if it is, add to running list
ads += curValue + ',';
}
//reset previous value
prevValue = curValue;
}
//remove last comma from string
if(ads.slice(-1) === ','){
ads = ads.slice(0, -1);
}
//convert string to array
outputs.ad_array = ads.split(',');
})(inputs, outputs);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 05:37 AM
This isn't working for me either. Is it working for you if you try to do this in a Custom Script exactly as I have described? I am wondering if I need to change the type of the List Collector variable coming in to the Custom Action I am creating.
So far, neither of these two suggested methods I have done anything. My original was at least working, but it was just unnecessarily duplicating it if I made only exactly one selection.
It seems that brining List Collectors into Custom Scripts may behave a little bit differently than just manually creating one in the script, or trying it in a background script. I will take a look at the 3rd method suggested next.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 07:39 AM
If you really want exact script, then share the table information.
You didn't provide full details. As per your snap and the info provided by you "list_collector_value" should be of type string. But unfortunately it's showing as a reference type field in your last pic.
Share the inputs whatever you are passing to the subflow and check out the variable type.
Whatever the scripts suggested by the community members here will work only if you pass string value as an input.
Revisit your configuration again. Also provide more details.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 07:57 AM
If you are passing the list collector value and everything configured correctly,then it should look like below. (String values)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2025 05:32 AM
@jmiskey , I created this demo to provide you insights on how to create a custom action with Script Include.
Hope this helps.... How to Call a Script Include in a Custom Action Using Flow Designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 06:04 AM
I am not sure why I would need to do that instead of scripting right in the Custom Action. Is there some limitation?
I also do not see any reference it a List Collector in your demo. This Demo does not seem to geared to my question, as far as I can see.