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.

How to get all group name of current login user

ramesh_r
Mega Sage

Hi All,

 

I want to get all the group names of the current login user. instead of "GlideRecord" option i want to get the group name list.

 

I used the below script but return the sys id of all group name but i want to display value

 

var myGroups = gs.getUser().getMyGroups();
gs.info(myGroups);

4 REPLIES 4

Pooja Devkar
Mega Guru

Hello,

Try gs.log(gr.getDisplayValue()); or gs.log("Name:" +gs.getUser().getLastName());

Still you have any queries then feel free to ask.

Please mark correct & helpful; if it's useful to you.

Thanks & Regards,

Pooja Devkar

Hi 

 

I want to get the group name not user name

i user this below script but its not working

var myGroups = gs.getUser().getMyGroups().getDisplayValue();
gs.info(myGroups);

Did you tried the script provided below?

Alikutty A
Tera Sage

Hi,

Please try this script to get all group names

var myGroups = gs.getUser().getMyGroups().toString().split(",");

for(var i=0; i< myGroups.length; i++){

  var group = new GlideRecord('sys_user_group');

   if(group.get(myGroups[i])){

     gs.info(group.getDisplayValue());

   }

}