Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need assistance on reference qualifier.

dhineshkumar
Tera Guru

Hi Team 

I have the catalog item and have three fields When I select any user A field it automatically pop up the managers name(I appled the catalog data lookup definition). Now I want to show the third field (user B) number of users respective manager. 

dhineshkumar_0-1726743585757.png

 

Thanks in advance.

 

1 ACCEPTED SOLUTION

Nishant8
Giga Sage
Giga 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

11 REPLIES 11

Hi @dhineshkumar Got it, You want to set dynamic reference qualifier based on Manager field. 

Try below reference qualifier. Let's see it if works or not?

javascript: 'manager=' + current.variables.manager

and add below attribute 

ref_qual_elements=manager

 

@Sid_Takali 

should I have to apply on the User B field this dynamic and attribute.

Thank you.

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