closed incident showing users name instead of system servicenow

TarunChowdary
Tera Contributor

Hi Community,

 

I'm using a scheduled job to check the resolved incidents and close them after 5 weekdays with this code

 

updateRecords();
function updateRecords() {
    try {
        var inc = new GlideRecord('incident');
        inc.addQuery('state', 6); // State 6: Resolved
        inc.query();

        while (inc.next()) {
            var resolvedAt = new GlideDateTime(inc.resolved_at);
            var nowTime = new GlideDateTime();

            var days = getDateDiffExcWeekends(resolvedAt, nowTime);
           
            // If 5 business days have passed since resolution
            if (days >= 5) {
                inc.autoSysFields(false);
                inc.state = 7; // State 7: Closed
                inc.incident_state = 7;
                inc.active = false;
                inc.update();
            }
        }
    } catch (ex) {
        gs.info(ex);
    }
}

function getDateDiffExcWeekends(start, end) {
    var days = 0;
    while (start < end) {
        start.addDaysUTC(1);

        if (start.getDayOfWeekUTC() != 6 && start.getDayOfWeekUTC() != 7) {
            days++;
        }
    }
    return days;
}
 
but after the incident is closed my name is getting updated on the incident 
TarunChowdary_0-1744910395401.png

 

 Is it possible to change the name to system instead of my name?
 
6 REPLIES 6

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @TarunChowdary 

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0552820

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

JenniferRah
Mega Sage

Change your scheduled job to run as the System Admin.

Hi @JenniferRah Thanks for the reply,

Can you please tell me how to do that?

Go to the scheduled report table amd  from the list view, add the column run as and changed to system administrator.