Incident should not get resolved until all incident tasks associated with it gets closed

Shraddha desai
Tera Contributor

Incident should not get resolved until all incident tasks associated with it gets closed.

How to do this?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use Before update BR on incident table

Condition: State [Changes to] Resolved

Script:

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

	// Add your code here
	var inc = current.getUniqueValue();
	var gr = new GlideRecord("incident_task");
	gr.addActiveQuery();
	gr.addQuery("incident", inc).addOrCondition("parent", inc);
	gr.setLimit(1);
	gr.query();
	if (gr.hasNext()) {
		gs.addErrorMessage("Please close incident task before resolving incident");
		current.setAbortAction(true);
	}

})(current, previous);

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Tony Chatfield1
Kilo Patron

Hi, 1 option would be a before BR on state change (Close\Cancel) for the Incident table (or task table) that looks up your related task records and aborts the closure action if any of the sub tasks are still active.

This post appears to be a duplicate of this one

https://community.servicenow.com/community?id=community_question&sys_id=2d46e632db1e0510fd63250913961982

It is not necessary to create multiple threads for 1 question and if anything multiple threads are less likely to produce a clear response\answer.

Can you explain in step by step please? 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use Before update BR on incident table

Condition: State [Changes to] Resolved

Script:

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

	// Add your code here
	var inc = current.getUniqueValue();
	var gr = new GlideRecord("incident_task");
	gr.addActiveQuery();
	gr.addQuery("incident", inc).addOrCondition("parent", inc);
	gr.setLimit(1);
	gr.query();
	if (gr.hasNext()) {
		gs.addErrorMessage("Please close incident task before resolving incident");
		current.setAbortAction(true);
	}

})(current, previous);

Regards
Ankur

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

@Shraddha desai 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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