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

Elijah Aromola
Mega Sage

Yes that should print the number of records. I would recommend testing a fix script that updates a lot of records in a sub-production instance first.

Also look into using update multiple rather than looping through each record.

@Elijah Aromola - CloudPires - I just posted an example script. Records I am trying to really update are not the same per record, they are based off of a reference field from another table, so values will differ.

I just tried to run this and the row count was not printed. Am I missing something?

You have an extra ) at the end of your log line. 

@Elijah Aromola - CloudPires - Yeah I saw and removed it before running, but it still did not show the record count. Does this only apply to records that have been updated? If the fix script was ran once, and then getRowCount method was added, would it not pick it up?