Change Request unable to be moved to review until all tasks associated are closed.

Tyler Johnson
Tera Expert

Trying to make a change unable to be moved from implement to review unless all tasks are closed. I created a Dictionary override on the state so the state field is read only. This allows only the UI action to be used to progress the change. Im stuck trying to figure out how to block the change from progressing unless all tasks with this change are closed. 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use before update BR on change_request

Condition: State Changes From Implement AND State Changes To Review

Script:

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

	// Add your code here
	var cTask= new GlideRecord("change_task");
	cTask.addQuery("change_request",current.getValue("sys_id"));
	cTask.addActiveQuery();
	cTask.query();
	if(cTask.hasNext()){
		gs.addInfoMessage("your message to show to user");
		current.setAbortAction(true);
	}

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

Aman Kumar S
Kilo Patron

Hey,

You can have a before update BR, in which you can keep condition as State changes to Review, and in the script you can glide the change tasks table to check if there is any active record or not.

Sample script:

var changeTasks = new GlideRecord("change_task");
changeTasks.addQuery("change_request", current.getUniqueValue());
changeTasks.addActiveQuery();
changeTasks.query();
if(changeTasks.next()){
    gs.addInfoMessage('Change task/tasks are still active.');
    current.setAbortAction(true);
}

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Best Regards
Aman Kumar

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use before update BR on change_request

Condition: State Changes From Implement AND State Changes To Review

Script:

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

	// Add your code here
	var cTask= new GlideRecord("change_task");
	cTask.addQuery("change_request",current.getValue("sys_id"));
	cTask.addActiveQuery();
	cTask.query();
	if(cTask.hasNext()){
		gs.addInfoMessage("your message to show to user");
		current.setAbortAction(true);
	}

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Aman Kumar S
Kilo Patron

Hey,

You can have a before update BR, in which you can keep condition as State changes to Review, and in the script you can glide the change tasks table to check if there is any active record or not.

Sample script:

var changeTasks = new GlideRecord("change_task");
changeTasks.addQuery("change_request", current.getUniqueValue());
changeTasks.addActiveQuery();
changeTasks.query();
if(changeTasks.next()){
    gs.addInfoMessage('Change task/tasks are still active.');
    current.setAbortAction(true);
}

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Best Regards
Aman Kumar