- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 01:55 AM
I have catalog item with 2 variables employee and group. Employee is a reference field based on sys_user table. Group is also a reference field based on sys_user_group table. When I choose the value of the employee, i want to display only those group to which this employee belongs. How to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 02:42 AM - edited ‎03-01-2024 02:51 AM
Hi @vidhya_mouli ,
You can achieve this by creating script include and calling it through reference qualifier,
You can add reference qualifier in Group field like below,
javascript: new getuserGroup().getgroupDeatils(current.variables.user)
Script Include:
var getuserGroup = Class.create();
getuserGroup.prototype = {
initialize: function() {
},
getgroupDeatils: function(user){
var sysId = user;
var groupName = new GlideRecord('sys_user_grmember');
groupName.addQuery('user',sysId);
groupName.query();
var arr =[];
while(groupName.next()){
arr.push(groupName.group.toString());
}
gs.info('line number 15 ' + arr);
// gs.info('line number 16 ' + arr.toString());
// gs.info('line number 17 ' + arr.getDisplayValue());
return 'sys_idIN'+ arr;
},
type: 'getuserGroup'
};
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 01:57 AM
These will be helpful.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 02:08 AM
Below posts could be helpful :
Thanks & Regards
Amit Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 02:42 AM - edited ‎03-01-2024 02:51 AM
Hi @vidhya_mouli ,
You can achieve this by creating script include and calling it through reference qualifier,
You can add reference qualifier in Group field like below,
javascript: new getuserGroup().getgroupDeatils(current.variables.user)
Script Include:
var getuserGroup = Class.create();
getuserGroup.prototype = {
initialize: function() {
},
getgroupDeatils: function(user){
var sysId = user;
var groupName = new GlideRecord('sys_user_grmember');
groupName.addQuery('user',sysId);
groupName.query();
var arr =[];
while(groupName.next()){
arr.push(groupName.group.toString());
}
gs.info('line number 15 ' + arr);
// gs.info('line number 16 ' + arr.toString());
// gs.info('line number 17 ' + arr.getDisplayValue());
return 'sys_idIN'+ arr;
},
type: 'getuserGroup'
};
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 04:38 AM
I used exactly your code but struggling to get the values.
On group field:
javascript: new getuserGroup().getgroupDeatils(current.variables.employee_name)
Script Include:
var getuserGroup = Class.create();
getuserGroup.prototype = {
initialize: function() {
},
getgroupDeatils: function(user){
var sysId = user;
var groupName = new GlideRecord('sys_user_grmember');
groupName.addQuery('user',sysId);
groupName.query();
var arr =[];
while(groupName.next()){
arr.push(groupName.group.toString());
}
gs.info('line number 15 ' + arr);
return 'sys_idIN'+ arr;
},
type: 'getuserGroup'
};