User field should show users depending on the selection group selected in group field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2024 08:10 AM
Hi
I had requirement to allow the user to select multiple users (list collector type) on user field and users should be populated depending on the group selected on group field referring to sys_user_group table. Can you please help me how to achieve this. I have given a trail calling script include from user field and writing onchange client script but not working . I have given below reference qualifier as well by referring user field to group member table but created field is showing up as it has display value as true . I tried removing this dispaly value and adding other fields to show up using variable attributes but no luck, display value is showing up
javascript:"group="+current.variables.<group_variable_name>;
Can someone help on the script part how to achieve this
Thank you,
Anusha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 07:10 AM
you should be using advanced ref qualifier on the list collector variable
Script Include:
var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getMembers: function(groupId){
var id = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery("group", groupId);
gr.query();
while(gr.next()){
id.push(gr.getValue("user"));
}
return "sys_idIN"+id.join();
},
type: 'UserUtils'
});
Also use this in the variable attributes for that list collector; without this it won't work in list collector variable
ref_qual_elements=groupVariableName
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 11:59 PM
Hi Ankur,
It is not working as expected. Instead group members it is showing all users from user table.
I have given as user field as list collector and written given script include and called this script include from reference qualifier like below
javascript:new PopulateUser().getUsers(u_group_name);
But no luck. I have simply tried using refernce qualifier by keeping user field to group member table but it is giving created date as display value of created date is true. But I don't want to change this as it is global change. Can you please help me with the solution
Thanks
Anusha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 06:32 AM
Hello,
I had similar requirement which I was trying to practice in my PDI. I used user removal field as List collector to sys_user table and the group selection field as reference to sys_user_group table so when the group is selected the user removal should show only the users are part of this group.
You should write script include which should be called from Catalog via Reference qualifier syntax "javascript: new scriptincludename().function(current);, the current record is passed inside the function to script include.
The Script is as below: