- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
I found this question on the community where they were looking for a solution to close the ticket after 3 business days. As we all know, for example the "autoclose" for incident doesn't count business days, it just goes for "days". Which pretty much leaves people setting a high value enough so it would take care most of the short holidays and the customers won't be angry. This solution can be used on all kind of tickets.
EDIT: I also put this as an "idea" on the community, so go in and vote for it and see if we can get it into a future release: Be able to use Business hours/days to autoclose ticket
I will use the following stuff to get it to work:
- Relative Durations. I use this to set the amount of business days I want it to wait until it closes. Using relative duration
- DurationCalculator. To calculate the duration with a schedule. Using DurationCalculator to calculate a due date
- Schedule Job. Then I'll put the code in a schedule job that runs how often you want it to run to check and close those tickets that are "due".
First step is to create a relative duration that fits the amount of days you want. You can easy find it under System Scheduler->Schedules->Relative Durations.
As you can see there are a few examples that you can either use or look to understand how it's build up.
But lets create a new one that we want to be "3 business days". It doesn't need to be more than this:
Copy the sys_id of this record, since you will be needing it later for the coding of the schedule job.
Next step will just to get the sys_id of the schedule you want to use. Just head to the schedule record and copy that sys_id as well.
Now we got all the nice things we need. So lets head to System Definition->Scheduled Job and press New. Choose "Automatically run a script of your choosing" and we get to the new record.
Here you can set how often you want it to run, but perhaps once a day would be nice and let's pick a time when we don't think so many people are working.
Remember to put all your code in an anonymous function so it variable etc. doesn't get messed up with other things that is running. If you don't do this, strange things can happen if you for example have two jobs running at the same time and both having a variable called for example gr.
Summary of the code below.
- Get the sys_id for the relative duration I want to use
- Query all the records I want to go through. Active is true and got a resolve date is the ones I want here.
- Loop through the records I get and check if its been more than 3 business days since it was set to resolve. If it is, close it.
(function(){
//Get the relative duration for 3 business days
var relDur = 'f3ae5fc70f0132004cf365ba32050eb9';
//get the incidents that we want to go through
var encQue = 'active=true^resolved_atISNOTEMPTY';
var gr = new GlideRecord('incident');
gr.addEncodedQuery(encQue);
gr.query();
while(gr.next()){
//Calculate and see if resolve date is more than 3 business days ago. And if, close the ticket.
var dc = new DurationCalculator();
//Load the schedule into our calculation through the function below
addSchedule(dc);
//Do the calculation and see if end date is before today
dc.setStartDateTime(gr.resolved_at);
if (!dc.calcRelativeDuration(relDur)) {
gs.error("*** calcRelativeDuration failed for record {0}", gr.number);
}
if (dc.getEndDateTime() < gs.nowDateTime()){
gr.setValue('state', 7);
gr.update();
}
}
function addSchedule(durationCalculator) {
// Load the "8-5 weekdays" schedule into our duration calculator.
var scheduleName = "8-5 weekdays";
var grSched = new GlideRecord('cmn_schedule');
grSched.addQuery('name', scheduleName);
grSched.query();
if (!grSched.next()) {
gs.error("*** Could not find schedule {0}.", scheduleName);
return;
}
return durationCalculator.setSchedule(grSched.getUniqueValue(), "GMT");
}
})();
That it, I hope it can give some ideas how to use the duration calculator for more fun stuff.
//Göran
- 14,495 Views
- « Previous
-
- 1
- 2
- Next »
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.