Notification should trigger for aging incidents

Avee90
Tera Contributor

Hello Folks,
Notifications should trigger to assigned user for open incidents if the incident reaches to 30th day, 60th day and 90th from the creation of incident. Can someone help to achieve this. I'm new to scripting.

3 REPLIES 3

Saurabh Gupta
Kilo Patron
Kilo Patron

This can be done using a scheduled job. For knowing that you have triggered the 30th, 60th and 90th notification, you should be creating a custom field.
Sample code which actually is for approvals :

var qString = "sysapproval.sys_class_name=sc_req_item^state=requested^source_table=sc_req_item";
var grApp = new GlideRecord('sysapproval_approver');
grApp.addEncodedQuery(qString);
grApp.query();
while (grApp.next())
{
	var firstDT = new GlideDateTime(grApp.getValue('sys_created_on'));
	var cdate = new GlideDateTime();
	var diff = gs.dateDiff(firstDT.getDisplayValue(), cdate.getDisplayValue(), true);
	var noti= grApp.getValue('u_approval_notification')+"";
	if(diff >= 259200  && (noti== '' || noti=='null')) //3 days == 259,200 seconds
	{
		gs.eventQueue("approval_reminder_1",  grApp, grApp.approver, grApp.approver);
		grApp.u_approval_notification = 'first_reminder_sent';
		grApp.update();
	}
	else if(diff >= 518400  && noti== 'first_reminder_sent'   ) //6 days == 518,400 seconds
	{
		gs.eventQueue("approval_reminder_2",  grApp, grApp.approver, grApp.approver);
		grApp.u_approval_notification = 'second_reminder_sent';
		grApp.update();
	}
	else if(diff >= 777600 && noti== 'second_reminder_sent' ) // 9 days == 777,600  seconds
	{
		gs.eventQueue("approval_reminder_3",  grApp, grApp.approver, grApp.approver);
		grApp.u_approval_notification = 'third_reminder_sent';
		grApp.update();
	}

	else if(diff >= 1036800  && noti == 'third_reminder_sent') //12 days == 1,036,800 seconds
	{
		gs.eventQueue("approval_reminder_4",  grApp, grApp.approver, grApp.approver);
		grApp.u_approval_notification = 'fourth_reminder_sent';
		grApp.update();
	}

	else if(diff >= 1296000 && grApp.getValue('u_comments_updated') == true && noti== 'fourth_reminder_sent') //15 days == 1,296,000 seconds
	{
		gs.eventQueue("approval_reminder_1",  grApp, grApp.approver, grApp.approver);
		grApp.u_approval_notification = 'fifth_reminder_sent';
		grApp.update();
	}
	else if(diff >= 1555200  && grApp.getValue('u_comments_updated') == true && noti == 'fifth_reminder_sent') //18 days == 1,555,200 seconds
	{
		gs.eventQueue("approval_reminder_2", grApp, grApp.approver, grApp.approver);
		grApp.u_approval_notification = 'sixth_reminder_sent';
		grApp.update();
	}

	else if(diff >= 1814400  && grApp.getValue('u_comments_updated') == true && noti == 'sixth_reminder_sent') //21 days == 1,814,400 seconds
	{
		gs.eventQueue("approval_reminder_3",  grApp, grApp.approver, grApp.approver);
		grApp.u_approval_notification = 'seventh_reminder_sent';
		grApp.update();
	}

	else if(diff >= 2073600  && grApp.getValue('u_comments_updated') == true && noti == 'seventh_reminder_sent') //24 days == 2,073,600  seconds
	{
		gs.eventQueue("approval_reminder_4",  grApp, grApp.approver, grApp.approver);
		grApp.u_approval_notification = 'eighth_reminder_sent';
		grApp.update();
	}



}



 


Thanks and Regards,

Saurabh Gupta

AishwaryaS
Tera Contributor

Hello Naveen Nimmala2,

Could you please try this simple one?

Please go to the navigator and open Notifications under the System Notifications and Emails. 
Once you open Notifications create new notification.

Give the proper name to the notification and add the table Here I added the Incident table.

Then you can give the condition as mentioned in the below snap attached.

AishwaryaS_0-1703052332955.pngAishwaryaS_1-1703052343710.png

Then you just add what you need to send to the assigned to user in the "  What it will contain "

then save it and preview it.

Let us know, if it is helpful.

Thank You

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Avee90 

 

Better to use the flow designer and avoid any scripting there.

 

Trigger -> Schedule

Action

Look Up record

created date before 30 day / 60 day / 90 days or use

LearnNGrowAtul_0-1703074162450.png

 

 

Then 

Action Notification.

 

 

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************