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

JaanisK
Kilo Contributor

Hello Shaik,

You can use a Schedule here.

Create a new file of Schedule type, add holidays as schedule entries.

When it is done, you can query the global Schedule table, where "name" is your schedule name. Then, if a given day is within the schedule (checked by .isInSchedule call on GlideSchedule object), it is a holiday and you need to choose a different day.

I hope it helps.

Hi @JaanisK 

 

Thank you for the reply. I already have the OOB 8-5 weekdays schedule which i need to use can you please help me with the code to apply this

Tony Chatfield1
Kilo Patron
Hi, if you used a repeating OLA commitment you could trigger notifications on breach and also utilise the data for reporting on update frequency, driving improved client services and better user practice/ process. Even better it's all simple OOB functionality.

Hi tony,

 

I do have few more things to do with those ticket update the work notes etc thats why i am going with scheudle job