Filter out users in a specific group from reference variable

cgedney
Giga Guru

I have a User Reference variable on a catalog item. The BU does not want their names to be in the list of users. I created a script include: 

filterOutByGroupName: function(group_name) {
      /* Will remove users of the specified group from the list */
      var found_users = [];

      var gr = new GlideRecord("sys_user_grmember");
      gr.addQuery("group.name", group_name);
      gr.addNotNullQuery("user");
      gr.query();

      while (gr.next()) {
         found_users.push(gr.user.sys_id.toString());
      }

      var ref_qual = "sys_idNOT IN" + found_users.join(",");

      return ref_qual;
   },

 

And I have added this to the Advanced Ref Qual: 

javascript: new UserFilterUtils.filterOutByGroupName('Reporting');

 

But, I am still getting the users from that group in the list. What am I doing wrong?

 

Thank you, Charles

1 ACCEPTED SOLUTION

Hi @cgedney,

 

Didn't go through the entire code but looks like it's missing a set of parenthesis

i.e.

new UserFilterUtils().filterOutByGroupName('Reporting');

 

Cheers

View solution in original post

7 REPLIES 7

Hi @cgedney,

 

Didn't go through the entire code but looks like it's missing a set of parenthesis

i.e.

new UserFilterUtils().filterOutByGroupName('Reporting');

 

Cheers

It's always those little things I don't notice, no matter how long I stare at it.

 

Thank you very much

I just copied/paste your reference qual. I noticed there's a semicolon at the beginning and It seems you are missing the () after the first function call. So it should be: 

javascript: new UserFilterUtils.filterOutByGroupName('Reporting');

 

Updated reference qualifier:

javascript: new UserFilterUtils().filterOutByGroupName(groupName);

 

If my answer helped you in any way, please then mark it as helpful/Accepted.