GlideRecord in scheduled job won't iterate through query

chrissanford
Kilo Explorer

I am trying to write a scheduled job that will set a custom field called 'has business approver' based on whether or not a business change reviewer exists for a CI. I want to do this for all CI's in CMDB with a service desk support team. For some reason, the while loop does not seem to iterate through all the CI's in the query but only a select few. Here is my code:

var ci = new GlideRecord('cmdb_ci');
ci.addNotNullQuery('u_service_desk_support_team');
ci.query();
gs.log('Row count: ' + ci.getRowCount());
var count = 0;

while (ci.next())
{
count = count + 1;

var change_reviewer = new GlideRecord('u_ci_change_reviewers');
change_reviewer.addQuery('u_configuration_item', ci.sys_id);
change_reviewer.addQuery('u_business_approver', true);
change_reviewer.query();

if (change_reviewer.hasNext()) {
    ci.u_has_business_approver = true;
}
else {
    ci.u_has_business_approver = false;
}

ci.update();

}
gs.log('Loop count: ' + count);

After execution, the following is output to the log:

Row count: 101503

Loop count: 5179

The 101503 is how many CI's with a service desk support team actually exist. Why is the loop only running for 5179 CI's?

15 REPLIES 15

robertyoung
Giga Contributor

Did you ever figure this out? Having a similar issue updating assets that also update CI's