- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 10:36 PM
Hi All,
We have a requirement where we need to populate a reference field with values from two different reference fields on the form.
Say a reference field "Implementation Group" which currently have dependent field as "Assignment group" on the form. So when a user pick the field it will show the group members from the group on the Assignment group field. \
But now we need to make the "Implementation Group" field to show the members from both "Assignment group" field and an another "Owner group" field. so that when a user picks Implementation field it will show both the assignment group and the owner group members.
Note: I tried adding the "Owner group" in the Dependent field of that implementation group field but couldn't achieve the result. Can we achieve it through reference qualifier? If so kindly provide your solution for this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 11:20 PM - edited 07-30-2023 11:21 PM
Hi @Lavanya Nagendr ,
Use script include as
//Script Include
var GroupMembers = Class.create();
GroupMembers.prototype = {
initialize: function() {
},
getGroupMembers: function(group1, group2) {
var grp1 = new GlideRecord('sys_user_grmember');
grp1.addQuery('group', group1);
grp1.query();
var grp2 = new GlideRecord('sys_user_grmember');
grp2.addQuery('group', group2);
grp2.query();
var grpMembers = [];
while (grp1.next()) {
grpMembers.push(grp1.user.sys_id);
}
while (grp2.next()) {
grpMembers.push(grp2.user.sys_id);
}
return 'sys_idIN'+ grpMembers.toString();
},
type: 'GroupMembers'
};
and call this from advance reference
javascript : new GroupMembers().getGroupMembers(current.variables.group1, currenet.variables.group2;
Note: Please adjust the variable names of group1 and group2 as per your environment
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 10:44 PM
you cannot add 2 fields as dependent.
You need to use advanced ref qualifier and use script include; pass values for both the fields.
the script include function will then return the sysIds you want
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
07-30-2023 11:32 PM - edited 07-30-2023 11:34 PM
Hi Ankur,
This is my script include, Kindly help me on this whether this is right or not?
Ref Qualifier: javascript:"u_implementation_group="+new global.PR_PopulateImpValByField().getFields(current.assignment_group,current.u_owner_group);
Script Include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 11:35 PM
Looks good; just small update here since u_implementation_group is reference type
I believe you have added this advanced ref qualifier on u_implementation_group field
Ref Qualifier: javascript;"sys_idIN"+new global.PR_PopulateImpValByField().getFields(current.assignment_group,current.u_owner_group);
Implementation group field is reference to which table?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 11:59 PM
Yes i have added this reference qualifier on "u_implementation_group" field and this field also referring to Group table.
the below reference qualifier didn't work. The reference field(u_implementation_group) shows no group members.
Ref Qualifier: javascript:"sys_idIN"+new global.PR_PopulateImpValByField().getFields(current.assignment_group,current.u_owner_group);