Creating Separate Catalog Tasks Based on List Collector Selection in Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 04:18 AM
Hello Community,
I'm currently working on a ServiceNow workflow attached to a catalog item, and I'm facing an issue. The workflow involves a switch activity where the values from a list collector field named "environment" are correctly displayed, and the result is returned as the sys_id of the selection.
However, the workflow seems to get stuck after the switch activity, and it's not progressing to the task creation activity. My specific requirement is to create separate catalog tasks based on the user's selection from the "environment" list collector, which references the question choice table.
Your assistance on this matter is highly appreciated, as this requirement is urgent. Thank you in advance for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 04:33 AM
You're going to have trouble getting a switch activity to work in this case as a list collector stores a comma-separated list of sys_ids, and any workflow activity is looking for one value to move forward. It sounds like you may need to create multiple tasks, if multiple environments are selected, which means you'll either need to create the tasks via a script, or have multiple IF activities, which would look like - if environment contains 'sys_id1' the yes path creates task1, and the yes and no paths go to if environment contains 'sys_id2' the yes path creates task2, and the yes and no paths go to if...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 04:47 AM
Can you help me with the script, so that I will try in my PDI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 04:52 AM
Try this script:
var list_collector = current.variables.<listcollectorfieldvariablename>;
var list = list_collector.split(",");
for(var i=0;i<list.length;i++)
{
var grt = new GlideRecord("sc_task");
grt.initialize();
grt.environment= list[i];
grt.insert();
}
This is a sample script. Please change your variable and field name in this.
Regards,
Shamma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 05:05 AM
It's best to create Catalog Tasks with the Catalog Task activity. When you do so with a script it's much more difficult to choose which variables to display on the task, and to get the workflow to move on once a/all tasks have been completed.