
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2020 03:33 AM
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
Scheduled job
Notification
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2020 04:07 AM
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).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2020 04:07 AM
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).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2020 04:20 AM
Thank you so much, it worked! 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2020 05:10 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2020 05:29 AM
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");