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

Tyler Johnson
Kilo Guru

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

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

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 🙂

 

View solution in original post

3 REPLIES 3

Ankur Bawiskar
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

Hi Ankur, 

 

Even after this business rule as per change model oob script tasks created by flow gets closed. Then how it can validate the condition?

 

OOB script:

(function (current) {
    var ga = new GlideAggregate("change_task");
    ga.addQuery("change_request", current.sys_id);
    ga.addQuery("active", 1);
    var qc1 = ga.addQuery("created_from", "workflow");
    qc1.addOrCondition("created_from", "flow");
    ga.query();
    return ga.getRowCount() === 0;
})(current);

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 🙂