Notification to be send when incident was auto closed(not manually closed by user)

Yue
Kilo Contributor

Hi guys,

Can you help me with my requirement. I need to send a notification when incident was automatically closed by the system. How can I implement this? I cant find a condition in notification that will satisfy the condition. As much as possible, I want to utilize the OOB functionality. Thank you!

1 ACCEPTED SOLUTION

Hi @Yue ,

yes, I agree with you. I cannot see any alternatives with modifying OOTB code. As it should result in one additional line of code (firing an event) handling the skipped record at the next update should be easy.

Kind regards
Maik

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

View solution in original post

6 REPLIES 6

Vaishnavi Lathk
Mega Sage
Mega Sage

Hello Yue,

How to trigger a notification on when an incident is closed? You should have an out of the box solution for this, search for System Notification -> Email -> Notifications on left tab. Filter by which table you want to see notifications. You should find (e.g. for table Incident) an "Incident Resolved" notification which is triggered when [Incident state] [changes to] [Resolved].

If you want to create another notification to inform that the incident is closed, create a new notification with this condition: [Incident state] [changes to] [Closed].

How would you trigger a notification that warns the user that his reply to a closed incident have been ignored and that he should create a new ticket? You can set notification conditions (e.g. Incident table) to [Incident state] [is one of] [Resolved, Closed] AND [Work notes] [changes]. You can send the notification on this case to the caller or maybe to the "updated by" user. How would you implement a notification that needs to be sent in the caller language only? Another notification to be set. Let's suppose you have users based in the US and Mexico:

Notification #1: When to send: [Caller.Location] [is] [United States] What will contain: Notification in English Notification

#2: When to send: [Caller.Location] [is] [Mexico] What will contain: Notification in Spanish

Regards,

VAISHNAVI

 

Mark as Helpful or make it as a correct if answer Appericated.

Maik Skoddow
Tera Patron
Tera Patron

Hi @Yue 

at first, you have to enable the auto close feature: https://docs.servicenow.com/bundle/quebec-it-service-management/page/product/incident-management/tas...

A scheduled job will invoke the Business Rule 'incident autoclose'. Have a look in that BR to understand how it works and find a proper condition for your email notification.

Kind regards
Maik

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Yue
Kilo Contributor
Hi Maik, So there’s a scheduled job already built and Business Rule? Then what I need to do is to associate my notifications there via event? Is that right?

Hi @Yue 

again: Have a look into the Business Rule 'incident autoclose'  to understand how it works:

autoCloseIncidents();

function autoCloseIncidents() {
	var ps = gs.getProperty('glide.ui.autoclose.time');
	var pn = parseInt(ps);
	var queryTime = new GlideDateTime();
	queryTime.addDaysUTC(-pn);

	if (pn > 0) {
		var gr = new GlideRecord('incident');
		gr.addQuery('incident_state', IncidentState.RESOLVED);
		if (gs.getProperty('com.snc.incident.autoclose.basedon.resolved_at', 'false') === 'true') {
			gr.addQuery('resolved_at', '<', queryTime);
		}
		else {
			gr.addQuery('sys_updated_on', '<', queryTime);
		}
		if (pm.isActive('com.snc.incident.mim')) {
			var mim = gr.addNullQuery('major_incident_state');
			mim.addOrCondition('major_incident_state', '!=', new sn_major_inc_mgmt.MajorIncidentTriggerRulesSNC().MAJOR_INCIDENT_STATE.ACCEPTED);
		}
		gr.query();
		while(gr.next()) {
			gr.incident_state = IncidentState.CLOSED;
			//  gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
			gr.active = false;
			gr.closed_by = gr.resolved_by;
			gr.update();
		}
	}
}

 As you can see there are no events fired but the incidents updated directly.

So either you find a conditions on email notification that fits your needs, or you extend the OOTB BR with firing an event.

Kind regards
Maik

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.