- 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,968 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
04-01-2019 12:03 PM
Where in here do you define number of days before closure?
is it
var pn = parseInt(ps);
so if it were to close after 5 days in resolved state, it would be
var pn = 5;
correct?