
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2017 06:00 AM
Hello SN Comm,
So I have had help with this in the past, and believe I got a lot accomplished.. However, I believe I missed an important piece and overlooked what I should have really done.
The OOB Incident Autoclose looks like this:
autoCloseIncidents();
function autoCloseIncidents() {
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
var queryTime = new GlideDateTime();
queryTime.addDaysUTC(-pn);
if (pn > 0) {
var gr = new GlideRecord('incident');
gr.addQuery('incident_state', IncidentState.RESOLVED);
gr.addQuery('sys_updated_on', '<', queryTime);
gr.query();
while(gr.next()) {
gr.incident_state = IncidentState.CLOSED;
// gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.closed_by = gr.resolved_by;
gr.update();
}
}
}
I was informed to correct this by adjusting accordingly.. as I need this to happen to HR Cases.. we do not use Incidents..
so I adjusted like so:
autoCloseHR_Cases();
function autoCloseHR_Cases() {
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
var queryTime = new GlideDateTime();
queryTime.addDaysUTC(-pn);
if (pn > 0) {
var gr = new GlideRecord('hr_case');
gr.addQuery('hr_case_state', HR_Case_State.RESOLVED);
gr.addQuery('sys_updated_on', '<', queryTime);
gr.query();
while(gr.next()) {
gr.hr_case_state = HR_Case.CLOSED;
// gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.closed_by = gr.resolved_by;
gr.update();
}
}
}
Does this seem correct or completely wrong?
Anyone able to help thank you!!
-Rob
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 06:24 AM
HI Robert,
If you are going to employ a schedule (to skip over weekends) and wait a certain number of days after then you'll need a scripted solution. The scriptless solution was designed to work with simple use cases of "if these records are found, then set these values on them." You've stated a more complex set of query parameters.
At this time I'm not available to create that solution for you. Apologies.
If you do not currently have talent in house to develop this, I recommend engaging with professional services from ServiceNow or one of our partners.
PartnerNow | Sales, Services, Technology Partners | ServiceNow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 06:28 AM
Thanks Chuck! I get what you are say - and I will figure something out for this..
thanks for everything!
Cheers,
-Rob