Reference qualifier to return list of users

tsoct
Tera Guru

Hello all,

The script include should return group member or user with role, based on the condition. However, it isn't working. What might go wrong.

 

Thank you

var GetUsersUtils = Class.create();
GetUsersUtils.prototype = {
    initialize: function() {},

    GetListOfUsers: function(current) {
        var users = [];
        if (current.u_service_group == 'IT Services') {
            var memObj = new GlideRecord('sys_user_grmember');
            memObj.addQuery('group', '5c6dd3b98760a110bd37986adsdsdf'); //Group sys_id
            memObj.query();

            while (memObj.next()) {
                users.push(memObj.getValue('user'));
            }
        } else {
            var grUser = new GlideRecord('sys_user');
            grUser.addEncodedQuery('active=true');
            grUser.query();
            while (grUser.next()) {
                var grRole = new GlideRecord('sys_user_has_role');
                grRole.addQuery("user", grUser.sys_id);
                grRole.addEncodedQuery('role=c900c5e5fdgdfgdfge4a73a24ff6a746'); //role sys id
                grRole.query();
                while (grRole.next())
                    users.push(grUser.getValue('sys_id'));
            }

        }
        return 'sys_idIN' + users.toString();
		
    },

    type: 'GetUsersUtils'
};

 

 

 

1 ACCEPTED SOLUTION

AshishKM
Kilo Patron

Hi @tsoct, 

Add some gs.log inside the script include and check if while loop is adding sys_id of users and finally before return "is the users arraylist has some data or emtpy"

 

-Thanks,
AshishKM

View solution in original post

3 REPLIES 3

Mark Roethof
Tera Patron

Hi there,

 

This will help you solve your issue within minutes:
- 2020-10-21 - Blog - Q: Help!!! My code is not working! A: Did you debug your code?

AshishKM
Kilo Patron

Hi @tsoct, 

Add some gs.log inside the script include and check if while loop is adding sys_id of users and finally before return "is the users arraylist has some data or emtpy"

 

-Thanks,
AshishKM

I did and found the issue. Thanks