- 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
08-31-2020 01:01 AM
Hi Naveen,
As mentioned in my previous comment you will have to use schedule for calculation
I believe there are some scripts for this
Syntax
1) get the created date/time
2) using schedule add 5 days to this created date/time
3) you will get final date/time
4) check if this final date/time is same as today's date/time
a) if yes then email
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-31-2020 01:43 AM
Hi Naveen,
Sample script for 5 business 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);
if(isToday5BusinessDays){
gs.eventQueue('event.name', task, gs.getUserID(), gs.username());
}
}
}
function checkBusinessDays(createdTime){
var days = 5;
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
08-31-2020 11:46 PM
Hi Ankur,
Thanks for the script.
We are checking for 5 days.
How to check 2 days after 1st reminder and then again 2 days until state is closed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2020 11:59 PM
Hi Naveen,
So since you want to check 2 days after 1st reminder meaning you want to check for 5+2=7 days and then again for 2 days so 5+2+2=9
So you can accordingly modify the code for 7 and 9 days as you have reference for 5 days
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:11 AM
On the above script
dc.calcDuration(days*9*3600); // 9 hours is the schedule time from 8 to 5
Can this be done like,
5 days = 1st reminder.
2 days = 2nd reminder (2 days after the 1st reminder, 7th day)
2 days = 3rd and so on until state is closed.
It's gonna take reference from 1st reminder and then from 2nd and so on..
I'm not good with scripting.
I'm using Schedule jobs for the 1st time.
It would be really helpful if u can explain me in brief and help with the script.
Thank u so much