While loop is not working

Nisha B
Tera Expert

Hello All,

I have below code in schedule job which is written on Demand.

It is working correctly but evertime when I execute it update only 1 record it should update all the record if condition matches.

 

 var gr = new GlideRecord('incident');
 
        gr.addQuery('active',true);
        gr.addQuery('incident_state''-5');
        gr.addQuery('u_sub_status''Customer Action');
        gr.addQuery('assignment_group.company',"!=",'7c56caaadb79a81022d42de74b961945');
        gr.addQuery('sys_domain',"!=",'e534b9ecdb7b72001d83fd651d9619bb');
      gr.query();
        while (gr.next()) {
            gs.log("Number of incident in pending state customer action ",gr.getRowCount());
            diff= (gs.dateDiff(gr.sys_updated_on, gs.nowDateTime(), true));
            gs.log("Number of incident in pending state customer action difference time "+diff);
             if (diff>= 864000){
                 gs.log("Number of incident in pending state customer action test "+gr.getRowCount());
                gs.log('inside123PD test the record' + gr.number + ' age:' + gr.u_age_days);
                gr.incident_state = '6';
                gr.u_sub_status = 'No User Response';
                gr.close_notes = 'Two attempts have been made to reach the requester over email and no response has been received. Hence, incident has been automatically Resolved by the system after 10 days".';
                gr.close_code = 'No User Response';
                gr.u_resolved_by = 'System';
                gr.u_resolved = gs.nowDateTime();
                gr.active = false;
                gr.update();
                 gs.log("Number of incident in pending state customer action resolved today "+gr.number);
               
            }
        }
 
Can anyone please help why this while loop is not working.
 
Thanks
10 REPLIES 10

@Nisha B 

the error doesn't seem to have any link with your script

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader