How to send notification reminder for every 24hours up to 5days from the record created date.

Ajay37
Tera Contributor

Hi All,

How to send email notification for every 24hrs, until 5days from the creation date.

The first notification should be fired, after 24hrs the record got created. From then, the email should be sent for every 24hrs up to 5days.

Thanks

1 ACCEPTED SOLUTION

Hi,

gr.sys_created_by will give user name and not sys_id or email address

event parm1 requires either user sys_id or user email address

So I mentioned which field on termination task is referring to sys_user? use that field there

So that the event gets the user sys_id

OR if you are having any field on termination task which stores user email then use that there

Regards
Ankur

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

View solution in original post

22 REPLIES 22

Hi @Ankur Bawiskar ,

I have created scheduled job with the script you have updated and to test it I clicked on Execute now, but no notification is triggering.

find_real_file.png

find_real_file.png

find_real_file.png

find_real_file.png

Did any of the record has 30 days or 60 or 90 days as difference.

please test with correct records

are you having user field on your table which refers sys_user table

In Email notification is Event Parm1 contains recipient checkbox checked

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

Hi,

Did any of the record has 30 days or 60 or 90 days as difference?

No Ankur, the records were 7days old. 

please test with correct records. -- We are testing for records that are having created date less than 5days from now right. So 30days old records are not required? And I have created new records also, but no result.

are you having user field on your table which refers sys_user table?

I don't have custom field, I have created by OOB field.

In Email notification is Event Parm1 contains recipient checkbox checked?

I checked it to true and tested again, but not working.

 

Thanks

 

So are you testing with 5 days as difference between created time and now time?

Are there any records matching your condition of date/time difference

Try adding logs in the job script

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

Hi @Ankur Bawiskar ,

are you testing with 5 days as difference between created time and now time?

Yes Ankur, according to requirement, the notification should be sent for every 24hours upto 5days from the created date. If created date exceeds 5days then notification should be stopped.

In my instance, there are 11 records, which match with condition (days < 6)in the script and the script is working fine as it shows 11 log entries.

find_real_file.png

But notification is not getting triggered.

I have chosen Scheduled Script Execution under scheduled jobs and written below script there:

sendEmail();

function sendEmail(){
	try{
		var gr = new GlideRecord('u_termination_task');
		gr.query();
		while(gr.next()){
			var gdt = new GlideDateTime(gr.sys_created_on);
			var nowTime = new GlideDateTime();
			gs.log("gdt is: " + gdt);
			var duration = GlideDateTime.subtract(gdt, nowTime);
			var days = parseInt(duration.getDayPart());
			gs.log("duration is: " + duration);
			gs.log("days is: " + days);
			// if the difference is less than 6
			if(days < 6){
				gs.eventQueue('notification.remainder', gr, gr.sys_created_by);
				gs.log('check if condition: ');
			}
		}
	}
	catch(ex){
		gs.info('Exception'+ex);
	}
}

Notification:

find_real_file.png