Auto-Close Resolved Cases

Rob Sestito
Mega Sage

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

1 ACCEPTED SOLUTION

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


View solution in original post

25 REPLIES 25

Yes, the solution is an update set. Download it.



On your instance, go to Update Sets> Retrieved Update Sets, click Import Update Set from XML (on the list)



Upload the XML, then Preview the record and Commit it. Also, be sure to run the Fix script to update existing scheduled jobs to make use of the new features I add or you may have issues with existing jobs.


well - while in the update sets, I actually see 'Scriptless Scheduled Jobs v1.0.4', which is I believe the same file you and I are discussing now. It shows as loaded, but never committed. I guess I can just use that, preview it, commit it, and then run the Fix Script to update.



Going to process this - chat soon!


-Rob


You are correct. Loaded simply means you uploaded the update set. It won't be active and available until you Preview & Commit. The fix script is to ensure the legacy data works with the mods I made to the sysauto_script table.


Okay - now I have a dumb question but I need to ask it. I was always told no question is a dumb question - HAHA...



Do I need to create a new Fix Script, or is there one that should already be there that I need to run?



-Rob


Nvm - I found which one I needed to run.. it was simple... Update Scheduled Jobs..


Looks like my morning coffee is wearing off already..



-Rob