How to create multiple tasks using workflow

Arun61
Tera Contributor

we have a select box field with 1 to 10 choices when user select option 4 then 4 tasks should get created if i complete all four tasks then RITM state should complete if i incomplete the tasks then RITM state should be incomplete how can we achieved this using workflow can anyone please help me with the script. 

1 ACCEPTED SOLUTION

Sujatha V M
Kilo Patron
Kilo Patron

@Arun61  Please try to implement the use case in flow designer as per @Mark Manders

 

But if you still require it using workflow, below is a snippet of achieving the use case. 

 

1. Created a selected box variables with choices 1, 2, 3 

SujathaVM_0-1716795803219.png

2. Created a run script in workflow to create tasks dynamically

SujathaVM_1-1716795830184.png

Dynamic tasks creation based on the variable value selected: 

var length = current.variables.select_the_value;

for (var i = 0; i < length; i++) { 
    var task = new GlideRecord("sc_task");
    task.initialize();
	task.parent = current.sys_id;
    task.short_description = "Catalog Task creation count : " +i;
    task.request = current.request;
    task.request_item = current.sys_id;
    task.insert();
}

 

3. Wait until all the tasks are not active

checkCatalogTasks();
function checkCatalogTasks() {
var grTask = new GlideRecord('sc_task');
grTask.addQuery('request_item', current.sys_id);
grTask.addQuery('active', true);
grTask.query();
if(grTask.hasNext()){
answer = false;
}
else{
answer = true;
}
}

 

4. Validate if all tasks are "Closed Complete" or "Closed Incomplete"

SujathaVM_2-1716796032795.png

 

SujathaVM_3-1716796099198.png

5. Set the RITM state accordingly

 

SujathaVM_4-1716796135588.png

 

SujathaVM_5-1716796155015.png

 

Note: This works only if the catalog task states are same.  Incase of violation of states, it considers only the last updated record state. 

 

SujathaVM_6-1716796333107.png

 

SujathaVM_7-1716796363968.png

 

Modify the scripts as per your requirement for the other fields. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

View solution in original post

2 REPLIES 2

Mark Manders
Mega Patron

Why use workflow? Workflow is being replaced by flow designer and within the flow designer you can just drag and drop anything you need the flow to do.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Sujatha V M
Kilo Patron
Kilo Patron

@Arun61  Please try to implement the use case in flow designer as per @Mark Manders

 

But if you still require it using workflow, below is a snippet of achieving the use case. 

 

1. Created a selected box variables with choices 1, 2, 3 

SujathaVM_0-1716795803219.png

2. Created a run script in workflow to create tasks dynamically

SujathaVM_1-1716795830184.png

Dynamic tasks creation based on the variable value selected: 

var length = current.variables.select_the_value;

for (var i = 0; i < length; i++) { 
    var task = new GlideRecord("sc_task");
    task.initialize();
	task.parent = current.sys_id;
    task.short_description = "Catalog Task creation count : " +i;
    task.request = current.request;
    task.request_item = current.sys_id;
    task.insert();
}

 

3. Wait until all the tasks are not active

checkCatalogTasks();
function checkCatalogTasks() {
var grTask = new GlideRecord('sc_task');
grTask.addQuery('request_item', current.sys_id);
grTask.addQuery('active', true);
grTask.query();
if(grTask.hasNext()){
answer = false;
}
else{
answer = true;
}
}

 

4. Validate if all tasks are "Closed Complete" or "Closed Incomplete"

SujathaVM_2-1716796032795.png

 

SujathaVM_3-1716796099198.png

5. Set the RITM state accordingly

 

SujathaVM_4-1716796135588.png

 

SujathaVM_5-1716796155015.png

 

Note: This works only if the catalog task states are same.  Incase of violation of states, it considers only the last updated record state. 

 

SujathaVM_6-1716796333107.png

 

SujathaVM_7-1716796363968.png

 

Modify the scripts as per your requirement for the other fields. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.