Scheduled script for setting state of Security Incidents from Review to Closed after 3 days

modonnell
Tera Expert

Hello - trying to make a scheduled job to run a script that will go through all of the Security Incidents currently in the Review state that hasn't been updated in 3 days, and set the state to Closed. The Security Incidents will already have all the required fields when setting it to Review.

 

The below script I made is not doing anything when i hit the Execute Now button, any ideas what I am doing wrong here? First time trying to write a script in SN. Thank you.

 

try {
    var grSSR = new GlideRecord('sn_si_incident');
    grSSR.addQuery("active", "true");
    grSSR.addQuery("state", "100"); // review
   
    var threeDaysAgo = new GlideDateTime();
    threeDaysAgo.addDaysUTC(-3);
    grSSR.addQuery('sys_updated_on', '<', threeDaysAgo);
    grSSR.setLimit(1); // <- this is "( 1 )" without spaces here, keeps changing to icon.
    grSSR.query();
   
    while (grSSR.next()) {
        grSSR.state = 3; // closed
        grSSR.closed_at = new GlideDateTime();
        grSSR.closed_by = grSSR.assigned_to; // Set Closed By field to the current assigned to.
        grSSR.update();
    }
} catch (e) {
    gs.error(e.message);
}
6 REPLIES 6

Ankur Bawiskar
Tera Patron

@modonnell 

this is OOTB BR for incident closure, check the script and enhance for your table

AnkurBawiskar_0-1757435555488.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Ankur Bawiskar
Tera Patron

@modonnell 

Things to check in your script

1) state value is correct in comparision

2) you are using setLimit(1)  so it will try to match only 1 Record, comment that line

3) are you using correct field names for closed_at and closed_by

If my response helped please mark it correct and close the thread so that it benefits future readers.

@modonnell 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

@modonnell 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.