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

Keep the OOB BR to drive incident closure. You don't need one to drive the HR case auto close. It will trigger at the time specified (e.g. every day at 3:00AM or hourly, or whatever.


okay - Thanks again Chuck!


I will go forth and see what happens!


As always you have been a great help!!



-Rob


You are welcome. Let me know how it goes.


Hey Chuck - good morning!



So, I followed along your suggested condition:



Table: HR Case


Condition: State | is | (whatever) AND Updated | at or before | 2 days ago



Action:


Set field values: State | is | Closed



My actual:


Condition: State | is | Awaiting Acceptance AND Updated | at or before | (I do not have the option for 2 days ago - so I set it to 7 days


Action: (Same as yours)



I hit a couple of hours over 4 days and the case I was using to test with auto closed still. I wonder from within our conversation, did I mention I need this to happen 5 business days after it hits awaiting acceptance state? and also skip over weekend days..? If I forgot to mention that I deeply apologize.



Are you able to walk me through seeing how I can correct this? On the Action side, "Run Business Rule"   box was checked.. Should that remain? Also, There are 4 Relative Duration - would those have anything to do against this?



As always - I appreciate your help!


Chat soon,


-Rob


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