How to get number of records updated in fix script

mkader
Kilo Guru

Hello,

I have a simple fix script. After the update, I want to alert how many records were updated. How can I do this?

flagIncident();

function flagIncident() {
    var actIncGR= new GlideRecord('incident');
    actIncGR.addEncodedQuery('priority=4^sys_created_onONLast year@javascript:gs.beginningOfLastYear()@javascript:gs.endOfLastYear()');
    actIncGR.query();
    while (actIncGR.next()) {
        actIncGR.setWorkflow(false);
        actIncGR.autoSysFields(false);
        actIncGR.active = false;
        actIncGR.update();
    }
    
    gs.info("# of incident(s) updated: " + actIncGR.getRowCount()));

}

Does the below do what I need it to do?

There are thousands of records, so I do not want to BOG the system down and therefore am hesitant to try it.

Thanks

11 REPLIES 11

asifnoor
Kilo Patron

Hi,

If you have to send a email to anyone with the no. of updated records, then do like this.

1. Create a event on incident

2. Create a notification and listen to the event.

in the notification, add a mail script and do it lie this

template.print("Total no. of records updated are "+event.parm2.toString());

3. In the script make these changes.

flagIncident();

function flagIncident() {
    var actIncGR= new GlideRecord('incident');
    actIncGR.addEncodedQuery('priority=4^sys_created_onONLast year@javascript:gs.beginningOfLastYear()@javascript:gs.endOfLastYear()');

    actIncGR.query();
    while (actIncGR.next()) {
        actIncGR.setWorkflow(false);
        actIncGR.autoSysFields(false);
        actIncGR.active = false;
        actIncGR.update();
    }
    
gs.eventQueue("your_event_name",actIncGR,'',actIncGR.getRowCount());
    gs.info("# of incident(s) updated: " + actIncGR.getRowCount()));

Mark the comment as a correct answer and also helpful once worked.

The row count never popped up after the execution of the fix script