Hi @dhineshkumar Yes, 

@Sid_Takali 
Its not working.

Rajesh Chopade1
Mega Sage

Hi @dhineshkumar 

As per your question, you require count of users in third field (i.e. Manager 'Abraham linkon' having 20 members under him so you want to print count = 20 there & not a list of users)

If yes, you can utilize following 'onChange' script and 'script include' to achieve this requirement.

 

'onChange' script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var ga = new GlideAjax('CountUsersByManager');
    ga.addParam('sysparm_name', 'getUserCount');
    ga.addParam('sysparm_manager', newValue); // Pass the selected user's manager
    ga.getXMLAnswer(function(response) {
        g_form.setValue('user_B_count', response); // Assuming the field to show count is `user_B_count`
    });
}

 

Script include:

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

    getUserCount: function() {
        var managerSysId = this.getParameter('sysparm_manager');
        var userCount = 0;

        // Query the user table for users with the selected manager
        var userGR = new GlideRecord('sys_user');
        userGR.addQuery('manager', managerSysId);
        userGR.query();
        userCount = userGR.getRowCount();

        return userCount; // Return the number of users
    },

    type: 'CountUsersByManager'
};

 

And if you want to populate user list in field 3 instead of count then use following script include instead of above one.

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

    getUserNames: function() {
        var managerSysId = this.getParameter('sysparm_manager');
        var userNames = [];

        // Query the user table for users with the selected manager
        var userGR = new GlideRecord('sys_user');
        userGR.addQuery('manager', managerSysId);
        userGR.query();
        
        while (userGR.next()) {
            userNames.push(userGR.name); // Collect user names
        }

        return userNames.join(', '); // Return user names as a comma-separated string
    },

    type: 'GetUsersByManager'
};

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

 

vermaamit16
Kilo Patron

Hi @dhineshkumar 

 

@Rajesh Chopade1  has given a solution to your requirement using an On-Change client script. If you still prefer to use reference qualifier, you can take logic from the Script Include provided by him to get the count. Please note that the Script Include will not be Client Callable in that case so be aware of the syntax. This Script Include you can call within your reference qualifier to get the number of reportees under a manager.

 

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

Nishant8
Tera Sage

Hello @dhineshkumar, if you wish to display a list of users under the manager of user A, then you can write advanced qualification as follows: javascript:'manager='+current.variables.user_a.manager;

write this script under type qualification as below:

Nishant8_0-1726754585298.png

 

 

View solution in original post