gs.isMemberof() from User of dotwalking field

Meloper
Kilo Sage

hi,

i have to Check the Groups of an User.

I get the Userinformations from a Field through a GlideRecord

gr.board.owner.getValue()

No i have the SysId but how i can Check the Group or Roles?

 

 

find_real_file.png

1 ACCEPTED SOLUTION

Chavan AP
Tera Guru

hey hi Please try below:

function test(){var VTBOwner="9da66f651b3333009998da49cc4bcb63";//put VTBowner=grCard.board.owner.getVale();
var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('user', VTBOwner);
gr.query();
while(gr.next()) {

	if(gr.group=='0a52d3dcd7011200f2d224837e6103f2')// sys id of group1
		{
			gs.log('yes');
		}
	else {
		gs.log('no');
	}
 
	
} }
	test();

i have tested it output SS:

find_real_file.png

 

tthanks!!

if this helps then please mark if correct and helpful

 

Regards,

ajay

Chavan AP
[ Architect | Certified Professional]

Was this response helpful? If so, please mark it as Helpful and Accept as Solution to help others find answers.

View solution in original post

8 REPLIES 8

Sanjay Bagri1
Tera Guru

Yes, thanks. But i need a solution to get the Information of GS

 

I only have the User SYS ID i cant use gs..... 

if is use gs. i get the Userinformation of my admin

Himanshu Dubey
Giga Guru

Hi 

Use below condition in your script:

if(VTBOwner.hasRole('admin') && (VTBOwner.isMemberOf('assginment_group1') || VTBOwner.isMemberOf('assginment_group2'))

 

Please mark correct and Helpful if it helps

Thanks & Regards

Himanshu Dubey

Suseela Peddise
Kilo Sage

Hi,

Below code works for logged in user:

var currentUser = gs.getUser(); 
gs.info(currentUser.isMemberOf(­'Capacity Mgmt'));

If we have the user sys_id, isMemberOf() function may be won't work. I tried below, it doesn't work with user sys_id :

var usr= gs.getUserID(); // returns sys_id of the user record
gs.print(usr);
gs.print(usr.isMemberOf('Capacity Mgmt')); // it says undefined

 

gs.getUser(),Returns a reference to the user object for the current user. 

So, your code returns the sys_id of the user record.

May be you can use below:

var VTBOwner=gr.board.owner.getValue(); // assuming it returns user sys_id

var query= 'user='+VTBOwner 

+'^group=<<Group sys_id>>' //replace with group sys_id

+'^ORgroup=<<Group sys_id>>'; //replace with group sys_id

var grMem= new GlideRecord('sys_user_grmember);

grMem.addEncodedQuery(query);

if(grMem.next())
{

answer = true;

}

else

answer = false;

 

If I have answered your question, please mark my response as correct and/or helpful.

Thanks,

Suseela P.