- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2021 08:30 AM
Hello,
I have a scheduled script job that runs daily and any task not updated in 7 days, triggers an event which sends out a notification.
Now I have a requirements to send a follow-up email 5 days after that first notification has been sent.
How can I achieve this please?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2021 12:59 AM
yes nothing OOB
you can use Create Record action and set the fields correctly
Example
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2021 09:07 AM
Hi,
Should the follow up mail be sent always or is there any other condition like some flag which cheks after 1st notification is sent and before follow up mail to send?
Generally you send the ntoification to do some action. if that action is already done, then you don't need ot send follow up mail.
So here is how you shoudl do.
1. Create 1 event on the same table.
2. Trigger 1st mail.
in the mail script trigger this event to run after 5 days
var gdt = new GlideDateTime();
gdt.addDays(5);
gs.eventQueueScheduled("your_event_name",current, "","",gdt); //this will trigger after 5 days
3. now create a script action which listen to this event and check if the action is already done or do we need to send follow up mail? If you have to send follow up mail, then call your code which you are calling in scheduled job in this script action.
Mark the comment as a correct answer and also helpful if this has answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2021 09:13 AM
Thanks
So to give you some context, the first notification is only sent when the task SLA has been breached or there has been no update to the task for 7 days.
So i would need the 2nd notification to be sent 5 days after the first notification.
You mentioned step 2 create mail script, but in which notification?
also dont understand step 3, how do i create a script action?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2021 11:09 AM
Hi,
step2. In the 1st notification, add 1 mail script with the given code and that will trigger the event.
step3. Go to system policy -> events -> script actions and create new and select your event name there. In that add the code to trigger your 1st event (in the script action check if there is no update still. if no update, then trigger the notification like you were triggering from scheduled job)
Mark the comment as a correct answer and aslo helpful if this has answered the question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2021 11:41 AM
Thanks
Do I just copy my scheduled script job's code to the script action? or do I need to add some other logic?
This is my code from scheduled script:
The first query checks for breached SLA and calls the event, second one checks for tasks not updated for 7 days and calls event.
var query = "has_breached=true^task.active=true^planned_end_timeONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()";
var gr = new GlideRecord("task_sla");
gr.addEncodedQuery(query);
gr.setLimit(100);
gr.query();
while (gr.next()) {
if (gr.task.assigned_to == '') {
gs.eventQueue('no.update.7days.or.SLA breached',gr,gr.task.assignment_group.toString()); // for receipients manage the events parameters
}
else {
gs.eventQueue('no.update.7days.or.SLA breached',gr,gr.task.assigned_to.toString());
}
}
var queryUpdated = "active=true^sys_updated_onRELATIVELT@dayofweek@ago@6^sys_updated_onRELATIVEGT@dayofweek@ago@7";
var grUpdated = new GlideRecord("task");
grUpdated.addEncodedQuery(queryUpdated);
gr.setLimit(100);
grUpdated.query();
while (grUpdated.next()) {
if (grUpdated.assigned_to == '') {
gs.eventQueue('no.update.7days.or.SLA breached',grUpdated,grUpdated.assignment_group.toString());
}
else {
gs.eventQueue('no.update.7days.or.SLA breached',grUpdated,grUpdated.assigned_to.toString());
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2021 09:57 PM
Hi,
In your script action, you can add code like this.
var queryUpdated = "sys_id="+current.sys_id+"^active=true^sys_updated_onRELATIVELT@dayofweek@ago@6^sys_updated_onRELATIVEGT@dayofweek@ago@7";
var grUpdated = new GlideRecord("task");
grUpdated.addEncodedQuery(queryUpdated);
grUpdated.query();
if(grUpdated.next()) {
if (grUpdated.assigned_to == '') {
gs.eventQueue('no.update.7days.or.SLA breached',grUpdated,grUpdated.assignment_group.toString());
}
else {
gs.eventQueue('no.update.7days.or.SLA breached',grUpdated,grUpdated.assigned_to.toString());
}
}
Mark the comment as a correct answer and also helpful if this has solved the problem.