How To Limit Reference Choices Based on Different Variable

SuburbanGringo
Tera Contributor

Good morning,

 

I am attempting to create a new catalog item with two fields, "IT Application Support Group" and "Support Group Contact"

SuburbanGringo_0-1720460386272.png

The top box references the sys_group table, and the bottom box references the sys_user table. What I am trying to do is limit the options in the Support Group Contact reference to only show users that belong to the group selected in the IT Application Support Group box. So for example in the picture above, the Support Group Contact would only show users who are members of the Enterprise Architecture group.

 

Could someone please show or tell me how to accomplish this? Much appreciated in advance.

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

You reference qualifier on Support Group Contact would look similar to this:

BradBowman_0-1720465768811.png

Where GetGroupUsers is the name of a Script Include, getUsers is the name of a function in that SI, and v_support_group is the name of your IT Application Support Group variable.

 

Your Client callable Script Include would look like this:

var GetGroupUsers = Class.create();
GetGroupUsers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  getUsers: function(group) {
    var members = [];
    var groupMembers = new GlideRecord('sys_user_grmember');
    groupMembers.addQuery('group', group);
    groupMembers.query();
    while (groupMembers.next()) {
      members.push(groupMembers.user.toString());
    }
    return 'sys_idIN' + members.join(',');
  },

  type: 'GetGroupUsers'
});

 

Slava Savitsky
Giga Sage

To limit selection in a reference field, you need to use a reference qualifier.

 

If you only need active members of the group, you can reuse a method from the WorkflowApprovalUtils class in the code of your reference qualifier like this:

javascript: 'sys_idIN' + new global.WorkflowApprovalUtils().getMembersOfGroup(current.variables.name_of_your_first_field);

 

If you need all members, no matter if they are active or not, you could use the following reference qualifier:

javascript:'sys_idIN'+ getIDs(current.variables.name_of_your_first_field); function getIDs(grp) {var m = GlideUserGroup.getMembers(grp); var ids = []; while (m.next()) {if (!m.user.nil()) {ids.push(m.user.toString());}} return ids;}