How to filter module to only include groups I am a member of and of a certain type

Evren Yamin
Tera Contributor

Hello,

Is there a way to filter the module to only include groups that I am a member of and of a certain type?

For example on, My Groups Work, since I do not have an admin role, I need to only see 3 groups on the filter instead of 4 groups since the Change Manager group does not have an itil type.

Is there a way to hide this if the user is not admin?

find_real_file.png

 

1 ACCEPTED SOLUTION

Please modify the code as below

 

function getMyGroupsCustom()
{
var ids = [];
var uID = gs.getUserID();
var isAdmin=gs.getUser().hasRole('admin');
var grmember = new GlideAggregate('sys_user_grmember');
grmember.addQuery('user', uID);
grmember.addQuery('group.active', true);
if(!isAdmin)
grmember.addEncodedQuery('group.typeNOT LIKE2e763549d7111100828320300e61038d');
grmember.groupBy('group');
grmember.query();
while(grmember.next())
{
ids.push(grmember.group.toString());
}
return ids;
}

Add the highlighted code in your script include, it will work as you are expecting.

 

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta

View solution in original post

19 REPLIES 19

Oh nevermind, I know what I did wrong, apologies. It's working now though how can I make this only for non-admin users?

I mean this condition should only work if the logged in user does not have an admin role.

Oh nevermind, I know what I did wrong, apologies. It's working now though how can I make this only for non-admin users?

I mean this condition should only work if the logged in user does not have an admin role.

Please modify the code as below

 

function getMyGroupsCustom()
{
var ids = [];
var uID = gs.getUserID();
var isAdmin=gs.getUser().hasRole('admin');
var grmember = new GlideAggregate('sys_user_grmember');
grmember.addQuery('user', uID);
grmember.addQuery('group.active', true);
if(!isAdmin)
grmember.addEncodedQuery('group.typeNOT LIKE2e763549d7111100828320300e61038d');
grmember.groupBy('group');
grmember.query();
while(grmember.next())
{
ids.push(grmember.group.toString());
}
return ids;
}

Add the highlighted code in your script include, it will work as you are expecting.

 

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta

Hello,

It is now working, thanks so much for this. Appreciate all the help

Thanks


Thanks and Regards,

Saurabh Gupta