Auto close related tasks on change request closure...

Joel Pomales1
Tera Contributor

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!

3 REPLIES 3

Sulabh Garg
Mega Sage
Mega Sage

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.

Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

Rekha Esadkar
Tera Expert

Hi @author ,

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();

}

Gaurav Shirsat
Mega Sage

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