- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 12:53 AM
@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
2. Created a run script in workflow to create tasks dynamically
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"
5. Set the RITM state accordingly
Note: This works only if the catalog task states are same. Incase of violation of states, it considers only the last updated record state.
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.
Sujatha V.M.