Auto Create a ticket on calendar date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 02:14 PM
Is there a way to automatically create a ticket on a calendar date for a user to act on?
IE. On the first of the month a user needs to review the user list.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 08:15 PM
Hi David,
service-now provides the ability to automatically move incidents marked as 'Resolved' into a 'Closed' state after a certain number of days. In my experience I've found that this type of resolution/closure workflow is really the best way to configure your incident management setup because it allows end-users the ability to reopen incidents within a certain window (while they're still marked as 'Resolved') but it also ensures that eventually all of the incident tickets move to a 'Closed' state where they won't be reopened so that you can accurately calculate SLAs and reporting metrics.
The key piece to this auto close functionality is the 'incident autoclose' business rule on the 'Incident' table. It works in conjunction with the property shown here — that sets the number of days after which a resolved incident will be moved to a closed state. The 'incident autoclose' script works great but it is based off of a basic date calculation that doesn't take into account any business hours or holidays. Shown below are some modified versions of the 'incident autoclose' script that take into account the default system calendar (in the case of calendar-based autoclose), or your choice of any system schedule set up in your system (in the case of schedule-based autoclose).
Calendar-based Incident Autoclose Script
// and haven't been updated in a chosen number of days. You
// can set this number as a property in System Properties.
// If you want a comment placed in the incident, uncomment the
// 'gr.comments' line below.
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
if (pn > 0) {
var gr = new GlideRecord('incident');
gr.addQuery('state', 6);
gr.query();
while(gr.next()){
//Close any records that have not been updated in 'pn' number of days
//Date difference calculated based on default system calendar
var dif = gs.calDateDiff(gs.nowDateTime(), gr.sys_updated_on, true);
if(dif >= pn*86400){
gr.state = 7;
//gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.update();
}
}
}
Schedule-based Incident Autoclose Script
// and haven't been updated in a chosen number of days. You
// can set this number as a property in System Properties.
// If you want a comment placed in the incident, uncomment the
// 'gr.comments' line below.
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
if(pn > 0){
//Get a schedule by name to calculate duration
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', '8-5 weekdays');
if (typeof GlideSchedule != 'undefined')
var sched = new GlideSchedule(schedRec.sys_id);
else
var sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);
//Get the current date/time in correct format for duration calculation
var actualDateTime = new GlideDateTime();
actualDateTime.setDisplayValue(gs.nowDateTime());
//Query for resolved incident records
var gr = new GlideRecord('incident');
gr.addQuery('state', 6);
gr.query();
while(gr.next()){
//Close any records that have not been updated in 'pn' number of days
//Date difference calculated based on specified schedule
var dif = sched.duration(gr.sys_updated_on.getGlideObject(), actualDateTime).getDayPart();
if(dif >= pn){
gr.state = 7;
gr.active = false;
//gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
gr.update();
}
}
}
Schedule-based Incident Autoclose Script (BY HOURS!)
// and haven't been updated in a chosen number of hours. You
// can set this number as a property in System Properties.
// If you want a comment placed in the incident, uncomment the
// 'gr.comments' line below.
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
if(pn > 0){
//Get a schedule by name to calculate duration
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', '8-5 weekdays excluding holidays');
if (typeof GlideSchedule != 'undefined')
var sched = new GlideSchedule(schedRec.sys_id);