GlideRecord Query within Loop Not Working

sareshnaroji
Kilo Explorer

Hello,

We have an Wrapper Function with GlideRecord Query called within a For loop. The GlideRecord Query executes for the first time. However, for subsequent iterations .next(), .has next() returns false.

Any suggestion on using a GlideRecord Query within a for loop will be highly appreciated.

Regards,
Saresh

1 ACCEPTED SOLUTION

Saresh,



  Use this script



getAffectedClients();


function getAffectedClients(){


  var affected_clients = current.u_affected_clients.getDisplayValue();


  if(affected_clients.length!=0){//affected clients list


  getRelManagers(affected_clients);


}




function getRelManagers(rm_name){


  var gr_rm = new GlideRecord('u_rel_mamager_list');


  gr_rm.addQuery("u_client_name",'IN', rm_name);


  gr_rm.query();           //only first iteration runs successfully


  while (gr_rm.next()) {   //does not iterate second time gr_rm.next returns false


  var rel_manager = gr_rm.getValue('email');


  gs.addInfoMessage(rel_manager); //prints only records of first array object


  gs.eventQueue("affectedclients.notify", current, rm_name, rel_manager);


}


}


}


View solution in original post

10 REPLIES 10

Abhinay Erra
Giga Sage

You can always pass the entire thing and use IN operator in the glideRecord query. You do not need for loop at all.