Reference Variable Filtered by Group

Laurie Marlowe1
Kilo Sage

Hi,

I have a reference variable called "Project Lead".   I want to only show members of the Physical Security group in this field.   From what I've read it seems a reference qualifier should be used.   After reading some articles I tried entering the following:

Reference qualifier:   javascript:new GetGroupMember().getMember(bb3fc3056f68e10006a8f00dba3ee483)

I'm passing the sys_id of the Physical Security group.

Script Include:

var GetGroupMember= Class.create();

GetGroupMember.prototype = {

getMember : function(bb3fc3056f68e10006a8f00dba3ee483)

{

   

      var user_array = [];

      var getMembers = new GlideRecord('sys_user_grmember');

      getMembers.addQuery('group',bb3fc3056f68e10006a8f00dba3ee483);

      getMembers.query();

      while(getMembers.next())

              {

                user_array.push(getMembers.getValue('users'));

      }

      return 'sys_idIN' + user_array.toString();

}

};

What happens is I get the entire sys_user table unfiltered.   How do I just get the members of the Physical Security group so I can select one of them?

Any help is appreciated, as I am new to scripting.

Thanks,

Laurie

1 ACCEPTED SOLUTION

Please see my other reply as it will correct this situation.


View solution in original post

36 REPLIES 36

Aditya24
Giga Expert

Hi All,

The above mentioned answers are definitely correct and very helpful. But I think we have a very simple way to do that.

Please follow this HI Article link: https://hi.service-now.com/kb_view.do?sysparm_article=KB0831564

 

Instructions

It is filtering the sys_user reference list depending on the current value of the group field of the current record using an advance reference qualifier with the expression:

 

This approach could be applied to meet the customers requirement to display only active users that belong to a specific group with sys_id=Your group sys id

I suggest in your reference field you use an advanced reference qualifier with the following expression:

javascript:'active=true^sys_idIN'+getIDs("Your group sys id"); function getIDs(grp){var m=GlideUserGroup.getMembers(grp);var ids=''; while (m.next()){ids+= (m.user+',');} return ids;}


Please Mark Correct if it was helpful for you.

Thank you very much, Chris! Just what I was looking for!

Best regards
Thomas

Martin Bujold
Tera Contributor

Thanks a Bunch!
That is a life saver...

As mentioned above by Chrisfollow this HI Article link for detailed information...

This does exactly what I wanted, after troubleshooting for over an hour looking at other references, videos, documentation...

After watching this video from Chuck Tomasi, I realized I used the wrong reference table!

I had mistakenly referenced it to the Group Members [sys_user_grmember] instead of using the User [sys_user] table.

So, plain and simple:

  1. Create a Reference Field referring to the following Table: User [sys_user]
  2. Configure the Dictionary for the newly created reference field (use Advanced View)
  3. Navigate to the "Reference Specification" tab
  4. Fill out the following fields:
    1. Reference: User
    2. Use reference qualifier: Advanced
    3. Reference qual: javascript:'active=true^sys_idIN'+getIDs("replace with your group sys_id"); function getIDs(grp){var m=GlideUserGroup.getMembers(grp);var ids=''; while (m.next()){ids+= (m.user+',');} return ids;}

Refresh your form and your new Reference Field should now display only the members of the group you have specified in the "Reference qual" above.

I know this might seem simple enough and I am repeating what most people said but I hope this will help someone out there not lose hours of their lives they won't be able to get back 😉

I hope this will help someone else out there!

Nadia10
Tera Contributor

Is it possible to adapt this ref qualifier to filter against two groups instead of just one? i.e. supply 2x sys id's?

imranf1
Tera Contributor

Been a while, but iirc isn't the GetGroupedUsers() second parameter a list? You can try supplying comma separated format e.g. "group1,group2".