fetch the list of users who are under my manager

Community Alums
Not applicable

This is a code written in one the script include which I am using in one of the variable in advance reference qualifier.  I am not getting the expected result. I am getting "no matches found in the drop down". Please help me to modify the code if I am doing something wrong here.

 

var managername ='';
                       var loggedInUserManager ='';
                    var a = new GlideRecord('sys_user');
                        //if (a.get(gs.getUserID()))
                            // managername =a.manager.name;
                    //managername = userID.getValue('manager');
                    //var loggedInUserManager ='';
                //loggedInUserManager = gs.getUser(). getRecord(). getValue('manager');
                    a.addQuery('manager',gs.getUser().getManagerID());
                    a.addEncodedQuery('active=true^u_worker_type=Contingent Worker');
                    a.query();
                   var users = '';
                    while (a.next()) {
            users = users + "," + a.sys_id;
        }
        return 'sys_idIN' + users;

1 ACCEPTED SOLUTION

Try as below,code and also check what are you getting in logs

var mgr =  gs.getUser().getRecord().getValue('manager');

gs.info(mgr);

var a = new GlideRecord('sys_user');
                    //a.addQuery('manager', gs.getUser().getRecord().getValue('manager'));
                    a.addQuery('manager', mgr );
                    a.query();
                    var users = [];
                    while (a.next()) {
                        users.push(a.getUniqueValue());
                    }
                    return 'sys_idIN' + users.toString();

Best Regards
Aman Kumar

View solution in original post

7 REPLIES 7

Try as below,code and also check what are you getting in logs

var mgr =  gs.getUser().getRecord().getValue('manager');

gs.info(mgr);

var a = new GlideRecord('sys_user');
                    //a.addQuery('manager', gs.getUser().getRecord().getValue('manager'));
                    a.addQuery('manager', mgr );
                    a.query();
                    var users = [];
                    while (a.next()) {
                        users.push(a.getUniqueValue());
                    }
                    return 'sys_idIN' + users.toString();

Best Regards
Aman Kumar

@Robin Kumar 

Is your issue resolved?

 

Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

Best Regards
Aman Kumar

palanikumar
Giga Sage
Giga Sage

I don't see any issue with this script. This has the following condition

Get all the users where the manager is same as the logged in user and u_worker_type=Contingent Worker

If u_worker_type is a choice field then make sure Contigent Worker is value not label

Thank you,

Palani

Thank you,
Palani