- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2020 12:06 AM
Hello Guys,
I need to send a reminder notification on HR case ticket .
For example: If I was assigned a case on Monday 1st June and the State is “Ready “or “Work in Progress” .
I would receive a reminder on the 5th business day after it’s been opened (6th July) and again 2 days after that (Wednesday, 8th July).
I would continue to receive the reminder every 2 business days until the State is changed to “closed complete”, “closed incomplete” or “suspended”.
Someone help me here schedule job script. Please.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2020 12:22 AM
Hi Naveen,
Something like this; updated the script for 5, 7, 9 days
HRreminder();
function HRreminder() {
var task = new GlideRecord('hr_task');
task.addQuery('short_description', 'receive draft');
task.addQuery('active', true);
task.query();
while(task.next()){
var isToday5BusinessDays = checkBusinessDays(task.sys_created_on, 5);
if(isToday5BusinessDays){
gs.eventQueue('event.name', task, gs.getUserID(), gs.username()); // your event name for 5 days reminder email
}
var isToday7BusinessDays = checkBusinessDays(task.sys_created_on, 7);
if(isToday7BusinessDays){
gs.eventQueue('event.name', task, gs.getUserID(), gs.username()); // your event name for 7 days reminder email
}
var isToday9BusinessDays = checkBusinessDays(task.sys_created_on, 9);
if(isToday9BusinessDays){
gs.eventQueue('event.name', task, gs.getUserID(), gs.username()); // your event name for 9 days reminder email
}
}
}
function checkBusinessDays(createdTime, days){
var gdt = new GlideDateTime(createdTime);
var dc = new DurationCalculator();
dc.setSchedule('090eecae0a0a0b260077e1dfa71da828'); // Schedule sys_id I have used 8-5 weekdays excluding holidays
dc.setStartDateTime(gdt);
dc.calcDuration(days*9*3600); // 9 hours is the schedule time from 8 to 5
var edt = new GlideDateTime(dc.getEndDateTime());
var nowTime = new GlideDateTime();
if(nowTime.getNumericValue() == edt.getNumericValue())
return true;
else
return false;
}
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
09-01-2020 12:22 AM
Hi Naveen,
Something like this; updated the script for 5, 7, 9 days
HRreminder();
function HRreminder() {
var task = new GlideRecord('hr_task');
task.addQuery('short_description', 'receive draft');
task.addQuery('active', true);
task.query();
while(task.next()){
var isToday5BusinessDays = checkBusinessDays(task.sys_created_on, 5);
if(isToday5BusinessDays){
gs.eventQueue('event.name', task, gs.getUserID(), gs.username()); // your event name for 5 days reminder email
}
var isToday7BusinessDays = checkBusinessDays(task.sys_created_on, 7);
if(isToday7BusinessDays){
gs.eventQueue('event.name', task, gs.getUserID(), gs.username()); // your event name for 7 days reminder email
}
var isToday9BusinessDays = checkBusinessDays(task.sys_created_on, 9);
if(isToday9BusinessDays){
gs.eventQueue('event.name', task, gs.getUserID(), gs.username()); // your event name for 9 days reminder email
}
}
}
function checkBusinessDays(createdTime, days){
var gdt = new GlideDateTime(createdTime);
var dc = new DurationCalculator();
dc.setSchedule('090eecae0a0a0b260077e1dfa71da828'); // Schedule sys_id I have used 8-5 weekdays excluding holidays
dc.setStartDateTime(gdt);
dc.calcDuration(days*9*3600); // 9 hours is the schedule time from 8 to 5
var edt = new GlideDateTime(dc.getEndDateTime());
var nowTime = new GlideDateTime();
if(nowTime.getNumericValue() == edt.getNumericValue())
return true;
else
return false;
}
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
09-02-2020 12:26 AM
Hi Ankur,
I tried the codes and executed the Schedule jobs.
But it missed.
Idk what needs to be done here. Please suggest if i'm missing something.
1.I have created 3 notification which are fired by 3 event.
2.Schedule job.
3. I clicked on execute now and this happened.
Please suggest and correct me if i'm wrong somewhere.
Thank you..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 12:41 AM
Hi Naveen,
Did you verify your job triggered or not?
I could see you are using some condition in your condition field of job
the last line of condition field should evaluate to true
so update as below
hr.hasNext();
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
09-09-2020 01:39 PM
I have similar requirement to send email reminder to the "HR Task Assigned to" after 3 business days the task created on. I am try using above script, execute it on demand, but emails are not triggered nor the event is getting created. I can see 8 hr task created 3 days before & active = true.
Created Event and notification......what I am missing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 01:51 PM
I have similar requirement - to send email reminder to Assigned to aster 3 business days. I am trying to use this script, but event is not created nor the emails are triggered.
I created Event & notification. Running On demand schedule job. I can see there are 8 HR task created 3 days back, and active = true.
What I am missing? can you please help.