List collect task scripting

neeluk
Tera Contributor

New to scripting and flow designer

I coped the script and replaced it with my specific variable from this post : Solved: Generating tasks from a list collector in a Servic... - ServiceNow Community

 

I'm looking to select groups from the list of 'Build/Test/Implementation groups' and create a task for each selected group.

neeluk_0-1719944037293.png

Keep getting this error, can someone please help

neeluk_1-1719944069519.png

 

This is my script

//list collect

var options = ((current.variables.build_test).toString()).split(','); //turns your list collector output into an array you can iterate through

{
   
for (i=0; i < options.length; i++) {

var tsk=new GlideRecord('sc_task');
tsk.initialize();
tsk.requested_for = current.requested_for;
tsk.request_item = current.sys_id;
tsk.short_description = 'Task for ' + current.cat_item.getDisplayValue() + " for " + current.variables.requested_for.getDisplayValue()  + " installing " + current.variables.equipment_type.getDisplayValue()  + " in the " + current.variables.install_location.getDisplayValue();
tsk.assignment_group = options[i];

tsk.insert();

}

}

 

 

 

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

The function declaration is usually present when you create a new Catalog Client script, but if you paste/type something, then change the Type of script it can get omitted.  You have pictured an onSubmit Catalog Client script, but the script was intended to be used in a workflow (server-side) Run Script activity.  So just for FYI, the Catalog Client script needs these first and last lines:

 

function onSubmit() {

}

but you wouldn't use an onSubmit Catalog Client script that applies to tasks to create Catalog Tasks, and server syntax like 'current', 'current.variables', etc won't work on client scripts.  These posts will get you closer to a solution if you are using Flow Designer in place of the Workflow Editor:

https://www.servicenow.com/community/developer-blog/using-list-collector-in-flow-designer-for-each-l... 

 

https://www.servicenow.com/community/developer-forum/looping-through-a-list-collector-to-have-catalo...