Triggering the notification three times and then close the problem ticket

Abhijeet Anand
Tera Contributor

Hello All,

I am trying to implement a functionality wherein, when problem ticket state changes to Resolved state, then it should trigger the notification(created by me) and then automatically close the problem ticket, after sending the notification three times to opened by and Created field user.

1. I have created an Event named "Problem.resolved.notify" and created the notification which will fire on the Event. i have not put any condition in the notification.

2. After that i have created a business rule on After ->Update with a condition, state changes to Resolved on the problem table and have added below script.

(function executeRule(current, previous /*null when async*/) {
var gdt = new GlideDateTime();
gdt.addSeconds(60);// 60 seconds because i want to trigger notification early in 1 minute.
gs.eventQueueScheduled('Problem.resolved.notify',gr,gs.getUserID(),null,gdt);

})(current, previous);

Currently it is not triggering any notification, Can you please let me know i am following the right approach and what could be the reason that it is not triggering any notification.

Thanks,

1 ACCEPTED SOLUTION

Hi,

Glad to know that it worked.

You can use script action and event for this

1) create event and link to your problem table. Problem.resolved.notify will be there; create new

2) create script action and link the event to this script action

3) from your BR trigger the event 3 times each with 1 min interval

4) when event gets processed the script action runs

5) in script action check the count and if it's 3rd then query the record and close it

a) Event name - trigger_event

b) Script action - trigger email

var count = event.parm2;
	gs.eventQueue("Problem.resolved.notify", current, gs.getUserID());

	if(count){
		var rec = new GlideRecord("problem");
		rec.get(current.sys_id);
		rec.state = 4;
		rec.update();
	}

c) BR Script:

(function executeRule(current, previous /*null when async*/) {
	var gdt = new GlideDateTime();
	gdt.addSeconds(60);// 60 seconds because i want to trigger notification early in 1 minute.
	gs.eventQueueScheduled('trigger_event',current,gs.getUserID(),1,gdt);

	gdt.addSeconds(60);
	gs.eventQueueScheduled('trigger_event',current,gs.getUserID(),2,gdt);

	gdt.addSeconds(60);
	gs.eventQueueScheduled('trigger_event',current,gs.getUserID(),3,gdt);

})(current, previous);

Regards
Ankur

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you should give current object but you gave gr

 

(function executeRule(current, previous /*null when async*/) {
    var gdt = new GlideDateTime();
    gdt.addSeconds(60);// 60 seconds because i want to trigger notification early in 1 minute.
    gs.eventQueueScheduled('Problem.resolved.notify',current,gs.getUserID(),null,gdt);
})(current, previous);

Regards
Ankur

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

Hello Ankur,

Thank you for your suggestion, it worked for me, however, could you please let me know the way i can trigger the same notification three times in one minute interval and after three notification the problem ticket should get automatically closed.

Should i write scheduled job for the same or write the same code which i wrote in business rule or is there any other way i can accomplish it through business rule only.

Thanks.

Hi,

Glad to know that it worked.

You can use script action and event for this

1) create event and link to your problem table. Problem.resolved.notify will be there; create new

2) create script action and link the event to this script action

3) from your BR trigger the event 3 times each with 1 min interval

4) when event gets processed the script action runs

5) in script action check the count and if it's 3rd then query the record and close it

a) Event name - trigger_event

b) Script action - trigger email

var count = event.parm2;
	gs.eventQueue("Problem.resolved.notify", current, gs.getUserID());

	if(count){
		var rec = new GlideRecord("problem");
		rec.get(current.sys_id);
		rec.state = 4;
		rec.update();
	}

c) BR Script:

(function executeRule(current, previous /*null when async*/) {
	var gdt = new GlideDateTime();
	gdt.addSeconds(60);// 60 seconds because i want to trigger notification early in 1 minute.
	gs.eventQueueScheduled('trigger_event',current,gs.getUserID(),1,gdt);

	gdt.addSeconds(60);
	gs.eventQueueScheduled('trigger_event',current,gs.getUserID(),2,gdt);

	gdt.addSeconds(60);
	gs.eventQueueScheduled('trigger_event',current,gs.getUserID(),3,gdt);

})(current, previous);

Regards
Ankur

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