Incidents are set to closed after 48 hours of being moved to 'Resolved state excluding weekends
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 10:39 PM
Hi All,
We have a custom table that is called "IT Incidents". After being resolved, these IT Incidents needs to be set to closed after 48 hours of being resolved and weekends should be excluded.
Can anyone please suggest.
TIA.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 10:52 PM
Hi @Nagashree5 ,
Check this link for solution. Please modify the days/time as per requirement.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 03:00 AM - edited 12-06-2023 03:01 AM
@Nagashree5 First you need to create a schedule record where you can exclude weekends and use in below script.
I have created script for incident table. You can modify for your table. You would need to create schedule job and put this script into it then schedule it for daily to run
var currentDateTime = new GlideDateTime();
var grIncident = new GlideRecord("incident");
grIncident.query('state', '6'); //get the resolved incidents
grIncident.query();
while(grIncident.next()) {
var dur = new DurationCalculator();
dur.setSchedule('090eecae0a0a0b260077e1dfa71da828'); // put the sys_id of schedule
dur.calcScheduleDuration(grIncident.resolved_at, currentDateTime);
var totalSecs = dur.getTotalSeconds();
d = Number(totalSecs);
var hours = Math.floor(d / 3600);
if (hours >= 48) // if total hours are more than 48
{
grIncident.setValue('state', '7'); //close the incident
grIncident.update();
}
}
Schedule -
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 05:19 AM
Hi @SANDEEP28,
Thanks so much for your response.
I have written the scheduled job with the provided code and created a schedule as well like below.
var currentDateTime = new GlideDateTime();
var grIncident = new GlideRecord("it_case");
grIncident.query('state', '150'); //get the resolved incidents
grIncident.query();
while(grIncident.next()) {
var dur = new DurationCalculator();
dur.setSchedule('c943f56187a7719056ed2f8f8bbb355c'); // put the sys_id of schedule
dur.calcScheduleDuration(grIncident.u_resolved_at, currentDateTime);
var totalSecs = dur.getTotalSeconds();
d = Number(totalSecs);
var hours = Math.floor(d / 3600);
gs.info("the hours are " + hours);
gs.info("the d are " + d);
if (hours >= 48) // if total hours are more than 48
{
grIncident.setValue('state', '7'); //close the incident
grIncident.update();
}
}
But, it is working for all the days, the hours are getting counted for weekends also, Can you please guide me on this.
Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 05:02 AM
@Nagashree5 If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!