Get User ID from sys_user_grmember

shiva_gupta
Mega Contributor

How to the user id and group name of all the user name   and group name listed in sys_user_grmember table using background script inside a variable or just   print those details .

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

Please use below background script to print user name and group name from sys_user_grmember table.



var sgp = new GlideRecord("sys_user_grmember");


sgp.addQuery('sys_id',"4c744323d711110050f5edcb9e6103e4"); // Please modify your query according to your requirements.


sgp.query();


while(sgp.next()){




gs.print("User id is " +sgp.getDisplayValue('user'));


gs.print("Group name is " + sgp.getDisplayValue('group'));




}


View solution in original post

14 REPLIES 14

just a little more help


gs.print("User id is " +sgp.getDisplayValue('user'))



above line only print the user name, actually i want to print the corresponding user id also.



but when i tried with


gs.print("User id is " +sgp.getDisplayValue('user.user_id'));


it return null



can you please suggest some modification.



again thanks for your time above code is really helpful


Hello Shiva,



As mentioned earlier you need to dot-walk to get user_id i.e code should be sgp.getValue('user.user_name')


Shiva,



Small correction. Replace user_id with user_name. User ID is the column label name. Sorry for the confusion.


hello pradeep



i tried below codes


sgp.getValue('user.user_id') ,


sgp.getValue('sys_user.user_name')


sgp.getValue('sys_user.user_id')


sgp.getValue('user.user_name')



but all are returning null



Can you paste your full query here