- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2017 01:51 PM
Hello,
We recently created a new BR so that if a RITM is Cancelled, the parent Request's state and stage would set to Cancelled as well since the oob BR (Close Parent if Required) would set the Request to Complete even if all RITMs were cancelled. I simply replicated the original BR and replaced the applicable values to reflect cancelled. This worked great until I realized that if a request has multiple RITMs, each with a different stage (complete, cancelled, rejected) the parent Request will now remain open. I suspect it is because each BR is running a query to make sure all other items have the same stage and since they do not, the request will not close. Any ideas on how to add a line into the script that checks all associated RITMs and close the parent request with the state and stage of complete if just one item closes as complete? Even if 5 RITMs are cancelled and/or rejected but 1 is complete, I need the Request to close as complete. I think modifying "Close Parent if Required" would be best, because the new BR for "Cancel Parent if Required" truly needs to run only if all RITMs are cancelled.
Thank you,
Heather Swearingen
closeParentIfRequired();
function closeParentIfRequired(){
// check to see if any of our peers are currently *not* closed
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('stage', '!=', 'complete');
//gr.addQuery('stage', '!=', 'Request Cancelled');
gr.query();
if (!gr.next()) {
// no peer task is currently open
var sc_request = new GlideRecord('sc_request');
sc_request.addQuery('sys_id', current.request);
sc_request.query();
sc_request.next();
gs.print("SC_REQUEST.STAGE = " + sc_request.stage + " INDEX = " + sc_request.stage.toString().indexOf('closed'));
if (sc_request.stage.toString().indexOf('closed') == -1) {
sc_request.stage = "closed_complete";
sc_request.comments.setJournalEntry("Request Automatically Closed as all Line Items were complete");
sc_request.update();
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2017 03:59 PM
Hi Heather,
You will need to declare another GlideRecord variable (gr3) instead of reusing gr2, I have modified your codes as below
closeParentIfRequired();
function closeParentIfRequired(){
// check to see if any of our peers are currently not closed
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('stage', '!=', 'complete');
gr.addQuery('stage', '!=', 'Request Cancelled');
gr.addQuery('stage', '!=', 'Final Rejected');
gr.query();
if (!gr.next()) {
// no peer task is currently open
//check if there is any sibling in complete stage
var gr2 = new GlideRecord('sc_req_item');
gr2.addQuery('request',current.request);
gr2.addQuery('stage','complete');
gr2.setLimit(1);
gr2.query();
//closed_complete if there's a single sibling in complete, otherwise cancelled
var new_stage;
if (gr2.hasNext()){
new_stage = 'closed_complete';
}
else{
var gr3 = new GlideRecord('sc_req_item');
gr3.addQuery('request',current.request);
gr3.addQuery('stage','Final Rejected');
gr3.setLimit(1);
gr3.query();
if (gr3.hasNext()){
new_stage = 'closed_rejected' ;
}
else{
new_stage = 'closed_cancelled';
}
}
var sc_request = new GlideRecord('sc_request');
sc_request.addQuery('sys_id', current.request);
sc_request.query();
sc_request.next();
gs.print("SC_REQUEST.STAGE = " + sc_request.stage + " INDEX = " + sc_request.stage.toString().indexOf('closed'));
if (sc_request.stage.toString().indexOf('closed') == -1) {
sc_request.stage = new_stage;
sc_request.comments.setJournalEntry("Request Automatically Closed as all Line Items were complete");
sc_request.update();
}
}
}
let me know how you go
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2017 03:59 PM
Hi Heather,
You will need to declare another GlideRecord variable (gr3) instead of reusing gr2, I have modified your codes as below
closeParentIfRequired();
function closeParentIfRequired(){
// check to see if any of our peers are currently not closed
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('stage', '!=', 'complete');
gr.addQuery('stage', '!=', 'Request Cancelled');
gr.addQuery('stage', '!=', 'Final Rejected');
gr.query();
if (!gr.next()) {
// no peer task is currently open
//check if there is any sibling in complete stage
var gr2 = new GlideRecord('sc_req_item');
gr2.addQuery('request',current.request);
gr2.addQuery('stage','complete');
gr2.setLimit(1);
gr2.query();
//closed_complete if there's a single sibling in complete, otherwise cancelled
var new_stage;
if (gr2.hasNext()){
new_stage = 'closed_complete';
}
else{
var gr3 = new GlideRecord('sc_req_item');
gr3.addQuery('request',current.request);
gr3.addQuery('stage','Final Rejected');
gr3.setLimit(1);
gr3.query();
if (gr3.hasNext()){
new_stage = 'closed_rejected' ;
}
else{
new_stage = 'closed_cancelled';
}
}
var sc_request = new GlideRecord('sc_request');
sc_request.addQuery('sys_id', current.request);
sc_request.query();
sc_request.next();
gs.print("SC_REQUEST.STAGE = " + sc_request.stage + " INDEX = " + sc_request.stage.toString().indexOf('closed'));
if (sc_request.stage.toString().indexOf('closed') == -1) {
sc_request.stage = new_stage;
sc_request.comments.setJournalEntry("Request Automatically Closed as all Line Items were complete");
sc_request.update();
}
}
}
let me know how you go
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2017 09:04 AM
This worked great. Thank you so much for your help!
Thank you,
Heather Swearingen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2017 03:47 PM
That's awesome, I'm glad to hear.
I believe that I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View.
Cheers,
Nam