Creation of multiple Sub tasks in order under multiple Parent Tasks

Sai62
Tera Contributor

Hi

I have a requirement to create sub tasks in order(Once the first sub task is completed, the other gets attached) under multiple parent tasks.

Scenario:
Based on the List collector field input on catalog item, I am creating multiple tasks under single RITM by utilizing the run script functionality in the workflow. This is working fine.

Run Script:

======================================================================

//pc_details is the list collector variable

var listStr = current.variables.pc_details.getDisplayValue();
var list = listStr.toString().split(",");
for (var i = 0; i < list.length; i++) {
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request_item = current.sys_id;
gr.assignment_group = current.variables.assignment_group;
gr.short_description = "PC Refresh for " + list[i];
gr.insert();
}

======================================================================

Now, in the multiple tasks that are created under RITM, we are in need of creating 5 fixed sub tasks under each of the parent task that will be assigned to the same group as that of the parent task.


Any inputs and ideas would be appreciated!!

1 REPLY 1

Shashikant Yada
Tera Guru

Add one more Run Script and below code: 

var subtask= new GlideRecord('sc_task'); //Parent Task
subtask.addQuery('request_item',current.item);
subtask.query();
while(subtask.next()){

for (var i = 0; i < 6; i++) {//Sub Task
var gr1 = new GlideRecord('sc_task');
gr1.initialize();
gr1.parent = subtask.sys_id;
gr1.request_item = current.sys_id;
gr1.assignment_group = current.variables.assignment_group;
gr1.short_description = "PC Refresh for " + list[i];
gr1.insert();

}
}