- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 08:11 PM
Hi,
we have a requirement where users who not updated incident assigned to them past 5 business days i want to send a notification to the assigned to & assingned to manager
For that i think i need to write a Scheudule job but can anyone please help me with the code to exclude the holidays & weekends ?
Below is the script which is working for 5 days but not for bsuiness days
var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^sys_updated_onRELATIVELE@dayofweek@ago@3');
gr.query();
while(gr.next())
{
gs.eventQueue('my.event', current, gr.assigned_to, gr.assigned_to.manager);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:58 PM
Hi Shaik,
try this script below; you will have to iterate over all incident records
that could be a limitation
var incident = new GlideRecord('incident');
incident.addActiveQuery();
incident.query();
while(incident.next()){
var updatedTime = incident.sys_updated_on;
var days = 5;
var dur = new GlideDuration(60*60*24*days*1000);
// paste the sys_id of the 8*5 weekday schedule excluding holidays and weekends
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
var finalTime = schedule.add(updatedTime, dur,'');
var updatedGdt = new GlideDateTime(updatedTime);
var finalTimeGdt = new GlideDateTime(finalTime);
// if the date/time after adding 5 business days is greater than updated time
if(finalTimeGdt > updatedGdt){
gs.eventQueue('my.event', current, gr.assigned_to, gr.assigned_to.manager);
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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
01-10-2020 07:04 AM
Hi Shaik,
Any update on this?
Can you mark my answer as ✅ correct, 👍 helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
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
05-20-2021 04:50 AM
Hi Ankur,
I have a requirement to send notification if incident is created 1 day ago and not assigned to any body.
I used your above mentioned code however it is not running after the glide schedule part.
Can you please check and suggest if i am doing something incorrect.
var INC = new GlideRecord('incident');
INC.addEncodedQuery('active=true^assigned_toISEMPTY');
INC.query();
while(INC.next()){
var updatedTime = INC.opened_at;
var ID = INC.sys_id;
var days = 1;
var dur = new GlideDuration(60*60*24*days*1000);
gs.log('Pooja Schedule' + updatedTime + ID);
// paste the sys_id of the 8*5 weekday schedule excluding holidays and weekends
var schedule = new GlideSchedule('a60f9281dbbc6300c53e3caf9d961945');
var finalTime = schedule.add(updatedTime, dur,'');
var updatedGdt = new GlideDateTime(updatedTime);
var finalTimeGdt = new GlideDateTime(finalTime);
// if the date/time after adding 5 business days is greater than updated time
if(finalTimeGdt > updatedGdt){
gs.eventQueue('my.event', current, gr.assigned_to, gr.assigned_to.manager);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 09:24 AM
Hi @Ankur Bawiskar ,
I checked the above script and trying to replicate with Procurement Case.I have written a script include on global with accessibility from all scopes,however receiving the following error.
Can't find method com.glide.schedules.Schedule.add(java.lang.String,com.glide.glideobject.GlideDuration,string). (sys_script_include.06b6a932977e69505b237886f053afe0.script; line 41) in:
getLastUpdatedindays: function() {
var pcrArr = [];
var pcGr = new GlideRecord('sn_spend_psd_procurement_request');
pcGr.addEncodedQuery('active=true^state=80');
pcGr.query();
while (pcGr.next()) {
gs.log('pcGr number '+pcGr.getValue('number'));
var updatedTime = pcGr.sys_updated_on;
gs.log('updatedTime '+updatedTime);
var days = 3;
var dur = new GlideDuration(60 * 60 * 24 * days * 1000);
// paste the sys_id of the 8*5 weekday schedule excluding holidays and weekends
var sched;
var grSchedule = new GlideRecord('cmn_schedule');
grSchedule.addQuery('name','08:30-17:30 Mon-Fri');
grSchedule.query();
while (grSchedule.next()) {
sched = new GlideSchedule();
sched.load(grSchedule.sys_id);
//var schedule = new GlideSchedule('dcc907c0db2c77005bcb24828a9619ad');
var finalTime = sched.add(updatedTime, dur);
var updatedGdt = new GlideDateTime(updatedTime);
var finalTimeGdt = new GlideDateTime(finalTime);
// if the date/time after adding 5 business days is greater than updated time
if (finalTimeGdt > updatedGdt) {
pcrArr.push(pcGr.getValue('sys_id')+'');
}
}
}
return pcrArr.toString();
}
Please note, even by using the exact script that you posted here ,albeit different schedule sys_id I am facing the same mentioned error.
Kindly note I need this for reporting.
Any responses on this would be highly appreciated.
Thanks,
Sri