- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2016 04:36 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2016 08:20 AM
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2016 04:41 AM
Could you please post your code here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2016 08:14 AM
OnBefore Business Rule Insert/Update
getAffectedClients();
function getAffectedClients(){
var affected_clients = current.u_affected_clients.getDisplayValue(); //affected clients list
var array_clients = affected_clients.split(",");
if(array_clients.length !=0){
for(var count =0; count < array_clients.length; count++){
getRelManagers(array_clients[i]);
}
}
function getRelManagers(rm_name){
var gr_rm = new GlideRecord('u_rel_mamager_list');
gr_rm.addQuery("u_client_name", 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.email.toString();
gs.addInfoMessage(rel_manager); //prints only records of first array object
gs.eventQueue("affectedclients.notify", current, rm_name, rel_manager);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2016 08:20 AM
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2016 06:18 AM
Thank you Abhinay, passing the entire list works fine for looping within the list items