Send Email Notification with Scheduled Job

Alex23
Kilo Guru

Hi All,

I have a requirement to send an email notification on a certain day of the month. I am trying to achieve this through an event using a scheduled job.

This is what I have so far in Dev to test this -

Event

find_real_file.png

Scheduled job

find_real_file.png

Notification

find_real_file.png

find_real_file.png

 

I believe the issue is with the script for the scheduled job?

Or is there a different/easier way to achieve this?

Any help would be much appreciated.

Thanks,
Alex

1 ACCEPTED SOLUTION

Okay. Then do it like this in your scheduled job.

var gr = new GlideRecord("incident");

gr.setLimit(1);

gr.query();

if(gr.next()) {

gs.eventQueue('patching_email',gr,gs.getUserName(),gs.getUserID());

}

Event/notification runs on a specific record. Since in your case, its just a static mail.. we just pass any 1 incident object. Hence using setLimit(1).

View solution in original post

18 REPLIES 18

Okay. Then do it like this in your scheduled job.

var gr = new GlideRecord("incident");

gr.setLimit(1);

gr.query();

if(gr.next()) {

gs.eventQueue('patching_email',gr,gs.getUserName(),gs.getUserID());

}

Event/notification runs on a specific record. Since in your case, its just a static mail.. we just pass any 1 incident object. Hence using setLimit(1).

Thank you so much, it worked! 🙂

Hi Again,

I have tested this with the job to run on a specific day of the month with no issues. 

However when I test with a condition, it does not send any email.

Condition

//3rd wednesday of month
checkDayOfMonth("Wed", "3");


function checkDayOfMonth(day, number){
	
	var result;
	var ordinals = ["", "1", "2", "3", "4", "5"];
	var date = String(new Date());
	var tokens = date.split(" ");
	var floatNumber = ordinals[Math.ceil(tokens[2]/7)];
	var weekDay = tokens[0];
	
	if(floatNumber == number && weekDay == day){
		result = true;
	} else {
		result = false;
	}
		
	return result;
	
}

The above code works with other jobs so can't see why it wouldn't work with this one.

Any ideas?

Thanks again,
Alex

The code is correct and it will run on 3rd wednesday of the month which is not today.

If you want to test, then test like this, as today is 2nd thursday of the month and you will get true.

checkDayOfMonth("Thu", "2");