- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2022 10:55 AM
I have a string array that I would like to pass to a list collector variable. Unfortunately it is only setting the last object in the array. How can I make it populate the entire array?
Script:
var seperate = answer.split(','); // "answer" is a comma seperated string
for (var i = 0; i < seperate.length; i++) {
g_form.setValue("test_list_collector_variable", seperate[i]);
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2022 12:30 PM
Hi,
What does "it didn't work" mean...because in this scenario, it wouldn't be the same reason that you've mentioned above.
I have no idea what your "answer" actually is...so please verify that.
Then...if it's a array of separated values, as you've mentioned, using:
seperate.join(',')
does in fact work, otherwise, if it's string from a script include that you're getting, for example, you can use:
g_form.setValue('field_name', answer.toString());
Again, as long as it's a comma separated list of sys_ids relevant to that field (reference is the right table and the values are sys_ids).
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2022 12:32 PM
Hi,
Thanks.
Yeah, I know what I mentioned above does work because I too made sure and just worked with someone else the other day around this whole thing.
It's most likely an error on the script side that is beyond what I've mentioned.
Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2022 12:57 PM
This is a client script so your server side script will not work. It is also on a Service Portal form.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2022 01:14 PM
Hi JJG,
I had tried this using JavaScript executer on the incident form and it works with the same logic in the client side as well. Refer below screenshot
Could you share some screenshot on what exactly you are trying to achieve and what output is being received.
Regards,
Deepankar Mathur

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2022 11:15 AM
Hi JJG,
Kindly use seperate [i].join(',') at the end.
Regards,
Deepankar Mathur