Creating separate tasks for each value in List Collector
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2022 02:52 PM
Hello,
Would it be possible to create a Workflow that would create X number of tasks, where X is the number of items selected in List Collector variable? For example, if user selected 2 items in List Collector, it should create 2 tasks, if 3 - then 3 tasks should be created. I found the script provided by @Mark Stanger that reads:
// Create 'sc_task' records for each item in the list collector var
var options = current.variables.list_collector;
// Iterate through the options
for (i=0; i < options.length; i++) {
// Query for the current CI
var ci = new GlideRecord('cmdb_ci_server');
ci.get(options[i]);
// Create a new task record for the current CI
var sct = new GlideRecord('sc_task');
sct.initialize();
sct.short_description = 'Task for ' + ci.name;
sct.assignment_group = ci.u_assignment_group; // Make sure this field name is correct!
sct.request_item = current.sys_id;
sct.insert();
}
However, no task is being created. Is it something with the code? Btw, it should work for workflows, not Flows.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2022 03:02 PM
Okay, it's solved. As advised by @William Coursen, modifying first line to
var options = current.variables.list_collector.toString().split(',');
did the trick 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2023 12:19 PM
Hello @Dawid2
How did you execute this? By chance are you able to provide a screenshot of where you implemented the code?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2024 07:02 AM