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

Gotcha!



I followed your link, ventured within my Instance to System Applications > Application, and received on the page: The entity name must immediately follow the '&' in the entity reference.



I tried researching that message and it looks like there is an issue with '&' being used on the sys_user table..? Do you know anything about that?



Thanks,


-Rob


So looking into it more - after following your link. I created a new role for Application Admin. While on the form, Assignable by is not showing however it added to the form. I went through UI Policies and UI Actions, and am unable to locate that to make it show on the form for me.



There is a chance I may not be able to go through route.



Thanks,


-Rob


So it didn't trigger when running as System?



Just so you're aware, this isn't just an issue with my Scriptless Scheduled jobs. It will need to be resolved for any scheduled jobs on the HR app. Let me see what I can come up with to help you on this...


This may not be an issue after all (scoped or global HR case.) Give it a try (using the proper table name. I ran some simple tests and don't think it will be an issue.


Okay - Thanks Chuck!



I have gone through and created the Scheduled Job with your update.



I have made my Scheduled Job that I showed you earlier inactive.



As for the OOB BR from the original post, can that stay or would that go away?



Thanks,


-Rob