Need help on getting tickets not updated for 5 business days

shaik_irfan
Tera Guru

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);

}

 

1 ACCEPTED SOLUTION

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Shaik,

you can use schedule calculation

1) get the last updated time stamp

2) add 5 business days to it and get that date/time

3) get the current timestamp when job run

4) if current date/time is more than date/time from step 2 it means 5 business days have crossed

do whatever is required

https://community.servicenow.com/community?id=community_blog&sys_id=314e26addbd0dbc01dcaf3231f961986

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

Can you please where do we have schedule calculation ?

 

Currently i have written a scheduled job as shown in the thread

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar ,

 

One question it means it sends an email for the tickets which are not updated on or before 5 business days.

 

 

Hi Shaik,

it checks those incidents which were updated 5 business days ago.

this is what is required right? any incident which has not been updated in last 5 business day

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader