- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 04:01 AM
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.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 07:03 AM - edited 09-19-2024 07:05 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 04:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 05:45 AM
@Sid_Takali
should I have to apply on the User B field this dynamic and attribute.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 05:45 AM
Hi @dhineshkumar Yes,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 05:49 AM
@Sid_Takali
Its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 05:01 AM
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