Change management

Community Alums
Not applicable

Hi,

 if all tasks are open change should not move to review. I tried a BR with code it is updating the closed task to canceled, It is not updating the open tasks to cancel. Can anyone help me on this.

 

5 REPLIES 5

Clara Lemos
Mega Sage
Mega Sage

Hi @Community Alums ,

 

Try doing one Business Rule in the Change Task table

With this conditions

Screenshot 2023-11-13 at 09.13.50.png

 And this code in the Advanced Tab

(function executeRule(current, previous /*null when async*/ ) {
    var changeTasks = new GlideRecord("change_task");
    changeTasks.addQuery("change_request", current.change_request).addCondition("active",true);
	changeTasks.query();
	while(changeTasks.next()){
		changeTasks.state='4';
		changeTasks.update();
	}
})(current, previous);

This Business Rule will cancel the other change tasks when one is Closed/Canceled

 

To avoid going to the Review State, add a business in the Change Request table as follow

Screenshot 2023-11-13 at 09.27.42.png

(function executeRule(current, previous /*null when async*/ ) {

    var changeTasks = new GlideRecord("change_task");
    changeTasks.addQuery("change_request", current.sys_id).addCondition('active', true);
    changeTasks.query();
    if (changeTasks.next()) {
        gs.addErrorMessage("open tasks which must be closed/canceled before reviewing this change record");
        current.setAbortAction(true);
        current.state = previous.state;

    }
})(current, previous);

 

If that helps please mark my answer as correct / helpful!
And if further help is needed please let me know

Cheers

Community Alums
Not applicable

Hi, 

Tried but not working eventhough one change task is closed other change tasks are still in open state.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi  @Community Alums 

 

Greetings!!

 

I am not sure what is the use case here. Bcz if you cancelled all task then task which are already closed will be moved to cancelled also, cancelling all task means no work done on change, and change marked as cancelled. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Community Alums
Not applicable

Hi,

If work done on one change task, that ctask will set to close , in that case if one change task for a particular change is closed all other change tasks of that particular change should set to cancel.