Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

checking group membership via Client script

bennyphipps
Giga Expert

Hi,

I have a Catalog Item where users can select a group and a list of users.   What I want is to look at that group members and set up an alert (or confirm) that says whether any of the users selected are already in that group

Or I guess I could do this maybe via altering the list collector filter?

My attempt at a client script that makes a GlideAjax call is:

function onSubmit() {

var group = variables.group; // group from reference variable on sys_user_group table

var users = variables.requested_for; //comma seperated list of users from list collector.

     

var ga = new GlideAjax('GroupMember');

ga.addParam('sysparm_name','groupMember');

ga.addParam('sysparm_group',group);

ga.getXML(GroupMemberParse);

function GroupMemberParse(response) {

    var answer = response.responseXML.documentElement.getAttribute("answer");

    alert(answer);

}

   

}

... and the script include is:

var GroupMember = Class.create();

GroupMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    groupMember: function() {

         

            var group = this.getParameter('sysparm_group');

            //return "Hello " + this.getParameter('sysparm_user_name') + "!";

            return _getusers(group);

    },

    _getusers: function(user) { // this function is not client callable        

  var strUsers = '';

  var grRole = new GlideRecord('sys_user_grmember');

  grRole.addQuery('user', user);

  grRole.query();

  while (grRole.next()) {

  if (strUsers.length > 0) {

  // build a comma separated string of groups if there is more than one

  strGroups += ',' + grRole.user;

  } else {

  strGroups = '' + grRole.user;

  }

  }

  return strUsers;

           

    }

});

6 REPLIES 6

yes, return = false should be in the onSumbit() function.


-Anurag

abhishek malik
Tera Contributor

i have the same use case and tried this code but it shows nothing to me. is this code is working on your instance