Is there a way to generate multiple tasks to various assignment groups via a script?

Cupcake
Mega Guru

Just wondering if there is a way to generate multiple tasks - 1 Task for each assignment group needed via a script.

Instead of creating multiple tasks, I want to create 1 task and inside of the task via the Advanced is there a script that can be used to generate additional tasks to other assignment groups.

Not sure if this is even possible.

find_real_file.png

 

Thanks,

Karen

6 REPLIES 6

bardakov
Tera Expert

You can create activity "Run script", and in it to create the necessary number of tasks using GlideRecord

can you share the code please

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Depending on how long until you upgrade to London, there is a really nice way to do it there with the flow designer. Here is an example:

find_real_file.png

for workflow you sadly need to script it instead.

scott barnard1
Kilo Sage

Like Viktor says you can use a run script

This is one based on a list collector variable that selects business services.

 

var varReferenceTable = "cmdb_ci_service";

 

var temp = current.variables.app_collection;


var tasks = temp.toString().split(",");


var variableRec = new GlideRecord(varReferenceTable);

 

//tasks.pop();

 

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


var gr = new GlideRecord('sc_task');


var user = new GlideRecord('sys_user');


user.get(tasks[i]);


gr.initialize();


gr.request_item = current.sys_id;



variableRec.initialize();


variableRec.get(tasks[i]);

var sgroup=variableRec;
gr.order =i;
gr.assignment_group = sgroup.support_group;
gr.short_description = gs.getMessage("Create Access to ") +' '+variableRec.getDisplayValue() + " - "+ current.u_item_requested_for.getDisplayValue();

 


gr.state = 1;


gr.insert();


}

 

So it creates a task with an order and a short description that includes the requested for and the name of the business service. Assigns it to the support group defined in the business service etc

 

We use it in access request items