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

SAI VENKATESH
Tera Sage
Tera Sage

Hi @cgedney 

 

You can change the below line :

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

 

Thanks and Regards

Sai Venkatesh

It is still showing the members of that group.

Hi @cgedney 

 

You can write the script include and call the script include as reference qualifier in the variable you needed.

change the values based upon your Requirement.

var rolesfilter = Class.create();
rolesfilter.prototype = {
    initialize: function() {
    },
	getRoles: function() {
            var userID = gs.getUserID();
            gs.info("The userID is: " + userID);

            var userRoleGR = new GlideRecord('sys_user_has_role');
            userRoleGR.addQuery('user', userID);
            userRoleGR.query();
			var roles=[];
            while (userRoleGR.next()) {
				roles.push(userRoleGR.sys_id.toString());
            }
			gs.info("roles are"+roles);
			return 'sys_idIN'+roles;
    },

    type: 'rolesfilter'
};

 

and in advance Reference Qualifier add this :

javascript:new rolesfilter().getRoles();

 

 

Thanks and Regards

Sai Venkatesh

 

cgedney
Giga Guru

I checked and I do have Client callable selected and the Script Include is active, but I am getting this error message:
com.glide.script.RhinoEcmaError: undefined is not a function.
<refname> : Line(1) column(0)
==> 1: new UserFilterUtils.filterOutByGroupName('Reporting');