Reference field with user selection linked to another reference field (similar to assignment group)?

Kiran_25
Tera Expert

I have added a 'assignment group'  field to a form, this references the group table and is populated by a business rule.

Next I have added a 'template owner' field which references the user table, where I want user selection linked to the 'assignment group'.  I can't use simple filters as the user table has no direct link to Group table.

I dont want to overcomplicated it & think there must be a straight forward way of doing this, i think there is something simple I am missing. 

 

When a user is completing the form and they go to the 'template owner' field, they should be presented with a list of users who are assignment group members for whatever assignment group is populated in that field.

 

2 REPLIES 2

Vishal Jaswal
Tera Sage

Hello @Kiran_25 

If you open any incident, select any assignment group, then you will notice the assigned to will show only those users who are members of your selected assignment group. So, you can take that learning and implement the same. This means you just have to add "Assignment Group Column Label" in the Dependent under Dependent Field tab of Template Owner dictionary:

VishalJaswal_0-1780066387468.png

VishalJaswal_2-1780066480455.png

 

VishalJaswal_1-1780066463547.png

 


Hope that helps!

Tanushree Maiti
Tera Patron

Hi @Kiran_25 

 

You can achieve this with a simple dynamic reference qualifier on your template owner field. Because group members are stored in the many-to-many relationship table (sys_user_grmember) rather than the user table itself, a dynamic reference qualifier using an include script is the easiest way to solve this.

 

try this.

 

1. Create a script include 

Set the Client callable checkbox to true

 

var getUserMembersByGroup = Class.create();
getUserMembersByGroup.prototype = {
initialize: function() {},

getGroupMembers: function(groupSysId) {
var userIds = [];
if (!groupSysId) return "sys_idIN";

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', groupSysId);
gr.query();
while (gr.next()) {
userIds.push(gr.user.toString());
}
return "sys_idIN" + userIds.join(",");
},

type: 'getUserMembersByGroup'
};

 

2. 

Apply the Reference Qualifier on Your Field

  1. Open the form with your custom fields.
  2. Right-click the Template Owner field label and select Configure Dictionary.
  3. Scroll down to the Reference Specification tab.
  4. Set Use reference qualifier to Advanced.
  5. In the Reference qual field, enter

javascript:new getUserMembersByGroup().getGroupMembers(current.assignment_group);

  1. Click Save or Update.

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti