update the ritm stage based on the completion of the tasks completion status
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 03:00 AM
Hi all, having a requirement,
Based on task completion status need to update the ritm stage.
we have below if script,
answer = ifScript();
var taskflag;
var approverflag;
function ifScript() {
var gr = new GlideRecord('sc_task');
gr.addEncodedQuery('stateIN4,7^request_item=' + current.sys_id);
gr.query();
if (gr.hasNext()) {
taskflag = true;
}
var gr1 = new GlideRecord('sysapproval_approver');
gr1.addEncodedQuery('state=rejected^sysapproval=' + current.sys_id);
gr1.query();
if (gr1.hasNext()) {
approverflag = true;
}
if (taskflag == true || approverflag == true) {
return 'yes';
} else {
return 'no';
}
}
based on the yes, no values updating the ritm stages.
but its not working of the task is skipped or closed incomplete.
need suggestions.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 06:20 AM
Hi @Community Alums,
Can I clarify my understanding of your question please...
Are you saying that the script (which looks to be an 'If Script' from a Workflow) is running correctly and as expected when a task is closed with the state of 'Closed Complete' (underlying database value of 3), but not when the task is closed with a state of either 'Closed Incomplete'(underlying database value of 4) or 'Closed Skipped' (underlying database value of 7) - Please confirm.
Based on my quick review of the code, I would make the following observations.
- What should happen to the Request Item when a task is Closed Incomplete or Closed Skipped? What state should the Request Item reflect? Should the Request Item reflect the same state, or should the Request Item be 'Closed Complete' for example? This is a process question
- Request Items can (and often do) have more than one Task associated, therefore, you should be checking to see if any other Task records exist and what their state is before updating the Parent Request Item.
If you're leveraging this via a workflow, you can implement a 'Wait for condition' and check all tasks are closed before updating the Request Item.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 10:10 AM
Hi @Robbie
Thanks for your response, please find the below inline comments for the queries.
Can I clarify my understanding of your question please...
Are you saying that the script (which looks to be an 'If Script' from a Workflow) is running correctly and as expected when a task is closed with the state of 'Closed Complete' (underlying database value of 3), but not when the task is closed with a state of either 'Closed Incomplete'(underlying database value of 4) or 'Closed Skipped' (underlying database value of 7) - Please confirm.
The above script is working as expected, In the current scenario of the catalog based on the check boxes it will trigger the approvals to associated groups once after approvals it will generate a tasks.
1- If all the tasks are closed complete then - request state = closed complete
2- if any one of the tasks gets closed incomplete / closed skipped - request state should be closed incomplete.
Based on my quick review of the code, I would make the following observations.
- What should happen to the Request Item when a task is Closed Incomplete or Closed Skipped? What state should the Request Item reflect? Should the Request Item reflect the same state, or should the Request Item be 'Closed Complete' for example? This is a process question
* RITM stage - request cancelled
* RITM status - closed incomplete
- Request Items can (and often do) have more than one Task associated, therefore, you should be checking to see if any other Task records exist and what their state is before updating the Parent Request Item.
If you're leveraging this via a workflow, you can implement a 'Wait for condition' and check all tasks are closed before updating the Request Item.
* we have a wait check for all the task completion. after completion based on the status we are updating as closed complete/ closed incomplete.
Currently we are getting stuck at approval part, if all the approvals are rejected then update the request to closed rejected. But its updating as closed incomplete.
I tried to explain your queries, hope it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 06:29 AM
Hello @Community Alums ,
Please give a try to the script below and see how it works for you also modify it further as per your need and business requirement.
var taskCompleted = false;
var taskSkipped = false;
var approverRejected = false;
// Check tasks
var taskGR = new GlideRecord('sc_task');
taskGR.addEncodedQuery('request_item=' + current.sys_id);
taskGR.query();
while (taskGR.next()) {
if (taskGR.getValue('state') == 4) { // 4 corresponds to 'Closed Incomplete'
taskCompleted = true;
} else if (taskGR.getValue('state') == 7) { // 7 corresponds to 'Skipped'
taskSkipped = true;
}
}
// Check approvers
var approverGR = new GlideRecord('sysapproval_approver');
approverGR.addEncodedQuery('sysapproval=' + current.sys_id);
approverGR.query();
if (approverGR.next() && approverGR.getValue('state') == 'rejected') {
approverRejected = true;
}
// Update RITM stage based on conditions
if (taskCompleted || approverRejected) {
current.stage = 'Closed'; // Modify this based on your actual RITM stages
} else if (taskSkipped) {
current.stage = 'Skipped'; // Modify this based on your actual RITM stages
} else {
current.stage = 'Open'; // Modify this based on your actual RITM stages
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket