Can we restrict  incident ticket while incident task is open

String
Kilo Sage

We are manually resolving the incident ticket ,but can we restrict the incident ticket to not to  resolve while incident tasks are in open state /work in progress 

 

Please suggest the best pratices 

 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@String Here is the BR which you need to create to restrict the incident from changing the state to Resolved if there associated open/work in progress tasks.

 

Screenshot 2023-05-09 at 1.03.38 PM.png

 

Screenshot 2023-05-09 at 1.04.23 PM.png

 

Here is the script.

 

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

	// Add your code here
	var glideIncidentTask = new GlideRecord('incident_task');
	glideIncidentTask.addEncodedQuery('incident='+current.sys_id+'^stateIN1,2')
	glideIncidentTask.query();
	if(glideIncidentTask.hasNext()){
		current.setAbortAction(true);
		gs.addErrorMessage('This incident has incident tasks which are either in opened or work in progress state.');
	}

})(current, previous);

Please mark this answer correct and helpful if it manages to address your requirement.

View solution in original post

10 REPLIES 10

Sandeep Rajput
Tera Patron
Tera Patron

@String Here is the BR which you need to create to restrict the incident from changing the state to Resolved if there associated open/work in progress tasks.

 

Screenshot 2023-05-09 at 1.03.38 PM.png

 

Screenshot 2023-05-09 at 1.04.23 PM.png

 

Here is the script.

 

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

	// Add your code here
	var glideIncidentTask = new GlideRecord('incident_task');
	glideIncidentTask.addEncodedQuery('incident='+current.sys_id+'^stateIN1,2')
	glideIncidentTask.query();
	if(glideIncidentTask.hasNext()){
		current.setAbortAction(true);
		gs.addErrorMessage('This incident has incident tasks which are either in opened or work in progress state.');
	}

})(current, previous);

Please mark this answer correct and helpful if it manages to address your requirement.

Hi @Sandeep Rajput  Thanks for your reply .

am tried the same code but still ticket is getting resolve with below error 

String_0-1683618518565.png

Please guide me 

@String After this error, it appears that the state is set to Resolved but if you refresh the page the state will revert back to previous state. This BR will not let the user change the state to Resolved until the child tasks are in Open and WIP state. 

@Thanks @Sandeep Rajput  got it ,After showing the error message can we refresh the ticket using same BR .So that user won't get confussed .am using the below syntax but not working 

gs.setRedirect (current.getLink(true));

 

 

 var glideIncidentTask = new GlideRecord('incident_task');
    glideIncidentTask.addEncodedQuery('incident=' + current.sys_id + '^stateIN1,2');
    glideIncidentTask.query();
    if (glideIncidentTask.hasNext()) {
        current.setAbortAction(true);
        gs.addErrorMessage('This incident has incident tasks which are either in opened or work in progress state.');
gs.setRedirect (current.getLink(true));
    }

 

Unfortunately, gs.setRedirect doesn't work along with current.setAbortAction(true) here is the knowledge article for it https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0539962