sujitha16
Kilo Patron

@Community Alums  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