Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Use getMyGroups() for a reference qualifier

apoorvmehta
Kilo Expert

Hi All,

I am trying to use getMyGroups() reference qualifier for populating only the groups that the current loggedin user is a part of for a new reference field.

I put the following condition in the reference qualifier but I am still able to see all the groups, :

gr.jpg

Don't know what I am doing wrong.

Any help would be appreciated.

1 ACCEPTED SOLUTION

CharlesR1
Kilo Guru

Hi Aropprv,



Not sure if you've fixed this yet, but if you haven't have a go at this. We had exactly the same problem. We fixed it by adding the following reference qualifier:



javascript:new BackfillAssignmentGroup12().BackfillAssignmentGroup12()



...and then creating a new client callable Script Include:



Name: BackfillAssignmentGroup12



Script:



var BackfillAssignmentGroup12 = Class.create();


BackfillAssignmentGroupNew.prototype = {


  initialize: function() {


  },



  BackfillAssignmentGroup12:function() {


  var gp = ' ';


  var a = current.gs.getUserID();



  //return everything if the assigned_to value is empty


  if(!a)


  return;


  //sys_user_grmember has the user to group relationship


  var grp = new GlideRecord('sys_user_grmember');


  grp.addQuery('user',a);


  grp.query();


  while(grp.next()) {


  if (gp.length > 0) {


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


  gp += (',' + grp.group);


  }


  else {


  gp = grp.group;


  }


  }


  // return Groups where assigned to is in those groups we use IN for lists


  return 'sys_idIN' + gp;


  },


  type: 'BackfillAssignmentGroup12'


}



Hope that helps



Charles


View solution in original post

5 REPLIES 5

apoorvmehta
Kilo Expert

I changed the script from : gs.getUser().getMyGroups() to getMyGroups() and it changed from Advanced qualifier to Dyanmic qualifier automatically, but still it is showing all the groups.


Michael Ritchie
ServiceNow Employee

IT should actually be just javascript:getMyGroups()


Hi Michael Ritchie, I had the intusion and already tried that, the ref qual changed to Dynamic view and took this shape, still it is not showing the membership groups:



ref.jpg



Please see the attached screenshot for both views.


CharlesR1
Kilo Guru

Hi Aropprv,



Not sure if you've fixed this yet, but if you haven't have a go at this. We had exactly the same problem. We fixed it by adding the following reference qualifier:



javascript:new BackfillAssignmentGroup12().BackfillAssignmentGroup12()



...and then creating a new client callable Script Include:



Name: BackfillAssignmentGroup12



Script:



var BackfillAssignmentGroup12 = Class.create();


BackfillAssignmentGroupNew.prototype = {


  initialize: function() {


  },



  BackfillAssignmentGroup12:function() {


  var gp = ' ';


  var a = current.gs.getUserID();



  //return everything if the assigned_to value is empty


  if(!a)


  return;


  //sys_user_grmember has the user to group relationship


  var grp = new GlideRecord('sys_user_grmember');


  grp.addQuery('user',a);


  grp.query();


  while(grp.next()) {


  if (gp.length > 0) {


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


  gp += (',' + grp.group);


  }


  else {


  gp = grp.group;


  }


  }


  // return Groups where assigned to is in those groups we use IN for lists


  return 'sys_idIN' + gp;


  },


  type: 'BackfillAssignmentGroup12'


}



Hope that helps



Charles