The CreatorCon Call for Content is officially open! Get started here.

check if logged in user is part oof anyone of the given groups

RC19
Tera Contributor

In a system property sys_xyz, we will have certain groups. In script include i need to check if user is part of anyone of the groups mentioned in that system property. Please suggest best practise on how to do this .

3 REPLIES 3

Samaksh Wani
Giga Sage

Hello @RC19 

 

For an example there is a system property :- glide-grp-name

 

 

 

 

 

var index = 'Group';
var props = gs.getProperty('glide-group-name');
var hashMap = JSON.parse(props); // Add global prefix if in scope
var answer = hashMap[index];  // answer will store the sysid of group.

gs.getUser().isMemberOf(answer);

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

 

Hi @Samaksh Wani,

 

Thanks for your reply. but actually my main concern is that my system property contains multiple groups . But isMemberOf() only works for single group i think . please suggest 

Hello @RC19 

 

For Multiple Group you can use 2 approach :-

 

1.   gs.getUser().isMemberOf(group1) || gs.getUser().isMemberOf(group2) ||         gs.getUser().isMemberOf(group3);

 

2. 

var groupsArray = ['CAB Approval', 'Change Management', 'xyz'];



for(var y=0; y < groupsArray.length; y++){

 

  var isMember = gs.getUser().getUserByID('abc').isMemberOf(groupsArray[y]);

 

}

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh