Closing the Cases after 10 days of being resolved
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 12:18 PM
Hello,
I have a request to auto close the cases that have been resolved for more than 10 days we have set up a business rule to mark the auto close box once we change the state to resolved, this is working right now, but for the old cases that we have resolved this is not the case they still showing as resolved in the system and they are not closed so i'm looking to schedule a job that close all the General Cases that have been resolved before 10 days but I'm struggling with the script.
So, I'm wondering this if this is the right approach? and if yes can you please help with setting up the Scheduled Job?
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 01:34 PM - edited 01-25-2023 02:35 PM
Hi,
I think schedule job is the right approach.
autoclose();
function autoclose() {
var gr = new GlideRecord('your_case_table');
gr.addEncodedQuery('Your_query_means_resolved_case');
gr.query();
while (gr.next()) {
var firstDT = gr.resolved_at;
var scheduleID = gs.getProperty('24*5_Schedule');//You can change this with a sys_id of 24*5 schedule
var cdate = gs.nowDateTime();
var dc = new DurationCalculator();
dc.setSchedule(scheduleID);
var diff = dc.calcScheduleDuration(firstDT, cdate);
//gs.info("amu:"+diff+gr.number);
if(diff > 864000) //10 days==864000 seconds
{
gr.state = 3;//You can check your close value
gr.active = false;
gr.comments = 'Case automatically closed after 10 business days in the Resolved state';
gr.update();
}
}
}
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 02:35 PM
Thanks a lot Saurabh!! I think this is what I was looking for, I'll try it out.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 02:36 PM
Hi,
You can change the query condition, table and schedule sys_id as per your need.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 04:21 PM
Hi again Saurabh, for some reason the scheduled job did nothing when I ran it, I have tested it in the test environment, I have used the following
var gr = new GlideRecord(TableName);
gr.addEncodedQuery(state, 6);
then I right click next to the scheduled job name then Copy Sys_ID.
var scheduleID = gs.getProperty('scheduledJobSys_ID')
and for gr.state = 3; I have used the same value since I have it the same, please let me know if there is anything else I need to do to make it work. Thanks