- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 08:42 AM
Hello,
I am attempting to create a scheduled job to auto-close Cases from the Customer Service application. I tried to model it after the incident autoclose business rule and the Autoclose Incident scheduled job. I don't seem to be able to get it to work, and I was wondering if anyone could provide some insight as to why it doesn't work? Here's the scheduled job:
Anyone able to help?
Thanks,
Shawn
Solved! Go to Solution.
- 4,967 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 11:59 AM
Hello Shawn,
Below is the sample script to close Cases which are in "Resolved'" state and are not updated in the specified number of days.
// This script automatically closes case that are resolved
// and haven't been updated in the specified number of days
// This number is a property in System Properties.
// To place a comment in the incident, uncomment the "gr.comments" line.
autoCloseCases();
function autoCloseCases() {
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('sn_customerservice_case');
gr.addQuery('state', 6);//Resolved
gr.addQuery('sys_updated_on', '<', queryTime);
gr.query();
while(gr.next()) {
gs.print("Case:"+gr.number);
gr.close_notes = 'Autoclose';
gr.active = false;
gr.closed_by = gr.resolved_by;
if((new global.StateFlow().validFlow(gr, 'd8069501c33231005f76b2c712d3aead', 'automatic'))){
new global.StateFlow().processFlow(gr, 'd8069501c33231005f76b2c712d3aead', 'automatic');
//d8069501c33231005f76b2c712d3aead : ID of state flow "Close Case"
}
gr.update();
}
}
}
Please also take a look at the state flow - "Close Case" defined for the Case (sn_customerservice_case), you can capture additional validations over here. For example, close_notes should be "Autoclose" or closed_by should be specific user etc.
Thanks,
Parag Mone

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 11:59 AM
Hello Shawn,
Below is the sample script to close Cases which are in "Resolved'" state and are not updated in the specified number of days.
// This script automatically closes case that are resolved
// and haven't been updated in the specified number of days
// This number is a property in System Properties.
// To place a comment in the incident, uncomment the "gr.comments" line.
autoCloseCases();
function autoCloseCases() {
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('sn_customerservice_case');
gr.addQuery('state', 6);//Resolved
gr.addQuery('sys_updated_on', '<', queryTime);
gr.query();
while(gr.next()) {
gs.print("Case:"+gr.number);
gr.close_notes = 'Autoclose';
gr.active = false;
gr.closed_by = gr.resolved_by;
if((new global.StateFlow().validFlow(gr, 'd8069501c33231005f76b2c712d3aead', 'automatic'))){
new global.StateFlow().processFlow(gr, 'd8069501c33231005f76b2c712d3aead', 'automatic');
//d8069501c33231005f76b2c712d3aead : ID of state flow "Close Case"
}
gr.update();
}
}
}
Please also take a look at the state flow - "Close Case" defined for the Case (sn_customerservice_case), you can capture additional validations over here. For example, close_notes should be "Autoclose" or closed_by should be specific user etc.
Thanks,
Parag Mone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2018 05:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 01:55 PM
Hi,
You will need to use correct state IDs based on the state flows that you have defined.
Alternatively, if you are on Kingston, you can make use of the Flow Designer to auto-close resolved cases. Flow Designer enables process owners to use natural language to automate approvals, tasks, notifications, and record operations without having to code Please take a look at the product documentation.
https://docs.servicenow.com/bundle/kingston-servicenow-platform/page/administer/flow-designer/concept/flow-designer.html
Thanks,
Parag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2018 07:56 AM
We had a similar issue where the scheduled job set up by our implementation vendor stopped working. I wasn't able to successfully troubleshoot the scheduled job issue but using the flow designer instead worked and was simple to implement. Thanks!