Auto close related tasks on change request closure...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2021 11:10 AM
I'm trying to figure out a business rule (script?) that runs when a change request has been marked as closed, it also closes all of the change tasks that are open.
I'm either debating this or a BR that tells the user that there are tasks open. Maybe have both options and let my stakeholders decide.
I know there's some scripting involved, but I can't figure it out.
Thanks!
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2021 11:32 AM
Hi Joel,
You may create one BR (Before, Update) which runs on trigger condition change request changes to closed. You may write below script in BR to check if any of the task is still open, It will throw a message to user as shown in script below.
var activeTask = new GlideRecord('change_task');
activeTask.addQuery('active',true);
activeTask.addQuery('change_request', current.sys_id);
activeTask.query();
if (activeTask.next()) {
gs.addErrorMessage('This Change Request has currently opened tasks, and cannot be closed. Please close any open tasks before closing this Requested Item');
current.setAbortAction(true);
}
Hope it helps.
Regards
Sulabh Garg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2021 08:05 PM
Hi
Check any after update business rule is present on change_request table with condition as state changes to close/cancel which queries the change task table for the current change request and closes that
If not then you need to have sample script as below
var task = new GlideRecord('change_task');
task.addEncodedQuery('change_request=' + current.sys_id + '^stateIN-5,1,2');
task.query();
while(task.next()){
task.state = 3; // move to close complete
task.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2021 09:31 PM
Hello
use my below script
Table:- Change_Request
write after BR with insert and update, with condition state changes to close
var actTask = new GlideRecord('change_task');
actTask.addQuery('active',true);
actTask.addQuery('change_request', current.sys_id);
actTask.query();
if (actTask.next()) {
actTask..state = 3;
actTask.update();
action.setRedirectURL(current);
;
}
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat