The CreatorCon Call for Content is officially open! Get started here.

Glide While loop only running once

Patrick Wachira
Tera Contributor

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

5 REPLIES 5

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);
    },