Want to send notification based on date field in catalog item

Burhan2
Tera Contributor

We have q request to send notification to requestedfor based on date. A date field is present in catalog item based on what is selected date on that field  before 1 day and after 1 day we need to send a notification. For ex:-if i select 25th date so on 24 and 26 need to send a email notification. Can anybody help me on this requirement

4 REPLIES 4

SP22
Giga Sage
Giga Sage

Hello @Burhan2,

Please find the below link and let me know whether it is helpful or not.

https://www.servicenow.com/community/developer-forum/creating-schedule-job-to-send-notification/m-p/...

you can follow the solution provided in the above link. but please create two schedule jobs, two events & two notifications to trigger.

1) First schedule job is for triggering notification 1 day before. create event and email notification for first schedule job.
2) second schedule job is for triggering notification 1 day after. create event and email notification for second schedule job.

Ensure that both schedule jobs are set to run daily so they can check the dates and send notifications accordingly.

You can find the sample schedule job scripts and modify as per your requirement.

var gr = new GlideRecord('sc_req_item'); // Change this to your table
gr.addQuery('u_selected_date', '=', gs.daysAgoStart(-1)); // 1 day before
gr.query();
while (gr.next()) {
    gs.eventQueue('your_event_before', gr, gr.requested_for, ''); // Event to trigger email
}

 

var gr = new GlideRecord('sc_req_item'); // Change this to your table
gr.addQuery('u_selected_date', '=', gs.daysAgoStart(1)); // 1 day after
gr.query();
while (gr.next()) {
    gs.eventQueue('your_event_after', gr, gr.requested_for, ''); // Event to trigger email
}


Thanks
SP.

Burhan2
Tera Contributor

Hey @SP22 when i am checking the emails i kept the schedule job to run daily....but both emails are getting triggered on the same day...as per my condition one email should be triggered after the expected date can you let me know why its happening??

Burhan2
Tera Contributor

@KarthikB9365919 did you used this script ??

Burhan2
Tera Contributor

@Ankur Bawiskar can you help me on this...this is not working the emails are triggering everyday and condition is not working