- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 11:25 PM
Hi all,
I have a reference field which refers to sys_user_group.
Another variable which is a list collector, it is referring to sys_user. Suppose, when user selects any group on the above field means I have to show users who are part of that group in the List collector variable.
Any leads.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 02:50 AM
Hi @Naga Ravindra R ,
It's because the typo. we should change the below line:
From
grMember.addQUery('group', group_id);
To
grMember.addQuery('group', group_id);
And also, the Reference Qualifier
From
new global.IOC_CheckOnboradingDate.getGroupMembersRefQual(current.variables.ioc_select_group2.toString());
To
new global.IOC_CheckOnboradingDate().getGroupMembersRefQual(current.variables.ioc_select_group2.toString());
You can refer to the screenshot, it works for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 12:31 AM
Let try this!
#Reference Qualifier
1. Write a function a the Script Include to build the Reference Qualifier
2. This function will have the group sys_id as input parameter.
3. Then, do the query to sys_user_grmember to get all members by group sys_id
4. And we return the encoded query as "sys_idIN" + the sys_id of all user members (collected from 3)
5. In the variable List Collector, we call the function => javascript: new <Script Include>.<Function Name> and pass the parameter as current.variables.group (the name of variable Group)
Sample below:
getGroupMembersRefQual: function(group_id){
if(gs.nil(group_id)){
return 'sys_id=NULL';
}
var memberIDs = [];
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQUery('group', group_id);
//grMember.addQuery('user.active', true);
grMember.query();
while(grMember.next()){
memberIDs.push(grMember.getValue('user'));
}
return 'sys_idIN' + memberIDs.join(',');
},
Reference Qualifier:
javascript: new global.SNCatalogUtil().getGroupMembersRefQual(current.variables.group.toString());
Besides, you can create an OnChange client script to clear the value of the List Collector whenever the Group variable changes.
#Autofill
So, if you're looking for the auto-populate feature (not a reference qualifier).
=> You can do the same way, just define your function in an AJAX Script Include. And the function need to be return the string of user's sys_id which is separated by comma.
After that, your Client Script will receive the response and just fill the result to the list collector variable.
Don't forget to let me know if it works for you.!
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 12:42 AM
Hello @Naga Ravindra R,
with the help of the above @Tai Vu code, you can achieve your requirements. Apart from this you need to give reference qualifier Attribute as below
no_filter = true,ref_qual_elements=<group_field_name> // replace your group field name
Please mark my answer helpful & correct, if it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 02:26 AM
Hey Guys,
Thank you for replying.
For some reason, it is not working. Please check below:
This is my function:
getGroupMembersRefQual: function(group_id) {
if (gs.nil(group_id)) {
return 'sys_id=NULL';
}
var memberIDs = [];
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQUery('group', group_id);
grMember.query();
while (grMember.next()) {
memberIDs.push(grMember.getValue('user'));
}
return 'sys_idIN' + memberIDs.join(',');
},
Reference qualifier:
javascript: new global.IOC_CheckOnboradingDate.getGroupMembersRefQual(current.variables.ioc_select_group2.toString());
variable attributes:
no_filter = true,ref_qual_elements=ioc_select_group2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 02:50 AM
Hi @Naga Ravindra R ,
It's because the typo. we should change the below line:
From
grMember.addQUery('group', group_id);
To
grMember.addQuery('group', group_id);
And also, the Reference Qualifier
From
new global.IOC_CheckOnboradingDate.getGroupMembersRefQual(current.variables.ioc_select_group2.toString());
To
new global.IOC_CheckOnboradingDate().getGroupMembersRefQual(current.variables.ioc_select_group2.toString());
You can refer to the screenshot, it works for me.