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

Anurag Tripathi
Mega Patron
Mega Patron

In the scheduled job you are passing gr but it is not defined, you should ideally use a glide record query for the record the email should be sent for, that would be your GR.

For Eg,

the scheduled job would be something like

gar gr = new GlideRecord('incident');

gr.get('<sys_id of an incident>');

gs.eventQueue('patching_email', gr, 'abc@example.com', '');

 

In this case the email would refer to the incident associated with gr

-Anurag

-Anurag

Hi Anurag,

Thanks for you help.

Can you please explain this one a bit more, I'm not sure why I have to include a sys_id of an incident and an email? And if I do, can this be any incident?

Thanks,
Alex

An email in ServiceNow is trigger against a record, it can be an incident, change, anything like that.

Can you tell me what is your email and what will it contain?

 

-Anurag

Hi Anurag,

The email is only text, it does not need to include any information regarding tickets.

Thanks!
Alex