While loop is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 03:47 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 04:16 AM
did you try adding try catch block to handle exceptions?
are you sure the difference is more than 864000 for those records
try{
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);
}
}
}
catch(ex){
gs.info(ex);
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 04:21 AM
Hello Ankur,
Thanks for reply,
I tried adding the try and catch but still not working,
almost 700 records are there I have set the limit to 50 in that almost 30 records have diff>864000 that should update , but it is not happening don't know why
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 04:30 AM
any other mandatory field you are forgetting to update while closing?
Did you check data policy is making any other fields as mandatory?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 04:33 AM
that job always update the 1 record only and if data policy is blocking then that 1 record should also be not updated then correct,