Glide While loop only running once
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2022 11:56 AM
I have a script include and function:
getRoleDescription: function(roleName) {
var role_descr;
gs.info(" Role Name = " +roleName );
var roleGR = new GlideRecord('x_XXXX_hcm_roles');
roleGR.addQuery('role_name', roleName);
roleGR.query();
roleGR.getRowCount();
return roleGR.getRowCount();
while (roleGR.next()) {
role_descr= roleGR.getDisplayValue('role_descr');
}
return role_descr;
},
it get called by
getRoleFromList: function(selected_roles, requestID) {
var roleArr = [];
if (selected_roles != "") {
var roles = selected_roles.split(',');
for (var x = 0; x < roles.length; x++) {
var roleObj = {};
roleObj.requestIDVal = requestID;
roleObj.role_name = roles[x];
//gs.info("Run 1 " + " In getRolesInfo " + " Role " + roles[x]);
roleObj.role_descr = this.getRoleDescription (roles[x]);
roleArr.push(roleObj);
} //eof for loop
} //eof if
return roleArr;
},
I have created a console comment and the function getRoleDescription receives all the a role runs it for the first time but returns no values for any subsequent run. Am not sure why it only runs once when its being called multiple times. Does anyone know why

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2022 06:23 PM
The problem then may not with these functions but with script calling getRoleFromList() to generate HTML.
If getRoleFromList is being called from a client, the result should be returned as a String and the client should parse JSON to get the object.
getRoleFromList: function(selected_roles, requestID) {
var roleArr = [];
if (selected_roles != "") {
var roles = selected_roles.split(',');
for (var x = 0; x < roles.length; x++) {
var roleObj = {};
roleObj.requestIDVal = requestID;
roleObj.role_name = roles[x];
//gs.info("Run 1 " + " In getRolesInfo " + " Role " + roles[x]);
roleObj.role_descr = this.getRoleDescription(roles[x]);
roleArr.push(roleObj.toString());
} //eof for loop
} //eof if
return JSON.stringify(roleArr);
},