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

It still needs to be tied to a record, that is just the way it is. I understand this is a limitation but this is how you can achieve this.

Since you don't need to include any information of a record, you can use any hardcoded test record to trigger the notifications.

You can pick any small table from your instance,  and just have this code below

var gr = new GlideRecord('<your table name>');

gr.get('<sys_id of any record on that table>');

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

 

Done 🙂

-Anurag

If your question is answered, please mark my response(or anyone else also if that helped you more) as correct/helpful and close the thread 🙂

-Anurag

-Anurag

mr18
Tera Guru
Tera Guru

Hi Alex,

If you want to send email for specific condition then try below code

var gr = new GlideRecord("incident");
gr.addQuery(<your query>);
gr.query();
while(gr.next())
gs.eventQueue('patching_email', gr);

 

or else try below code

var gr = new GlideRecord("incident");
gr.query();
if(gr.next())
gs.eventQueue('patching_email', gr);

HI,

This wont work as scheduled jobs don't have current object.

-Anurag

-Anurag

Yes you are right Anurag.

I have edited my answer