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 show the groups that the current user is a member of on Service Portal

Bruler1230
Tera Expert

Hello,

I have a form the service portal and I need to have a field that show the groups that the current logged in user is a member of. So when a user comes to the form, they will only see groups that they are part of in the dropdown. Should this be a reference field? Pretty sure I need to use a reference qualifier but wasnt able to figure it out. Thanks!

1 ACCEPTED SOLUTION

Allen Andreas
Tera Patron

Hi,

If you are only wanting to allow them to select one option, then yes, reference field to the sys_user_group table would work. You are also correct about needing an advanced reference qualifier which would be:

javascript:"sys_idIN" + gs.getUser().getMyGroups()

No other scripting required 🙂

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

9 REPLIES 9

Harsh Vardhan
Giga Patron

You should create on reference field which will refer to the sys_user_group table. 

Then Create one Script include:

 

Sample code:

 

var Get_group = Class.create();
Get_group.prototype = {
	initialize: function() {
	},

	getName: function(){
		var arr = [];
		var gr = new GlideRecord('sys_user_grmember');
		gr.addQuery('user',gs.getUserID());
		gr.query();
		while(gr.next()){
			arr.push(gr.group.toString());
		}
		return 'sys_idIN'+ arr;

	},

	type: 'Get_group'
};

 

Advance Reference Qualifier which you will use like below. 

 

javascript: new Get_group().getName()

Allen Andreas
Tera Patron

Hi,

If you are only wanting to allow them to select one option, then yes, reference field to the sys_user_group table would work. You are also correct about needing a reference qualifier which would be:

javascript:"sys_idIN" + gs.getUser().getMyGroups().toArray()

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Allen Andreas
Tera Patron

Hi,

If you are only wanting to allow them to select one option, then yes, reference field to the sys_user_group table would work. You are also correct about needing an advanced reference qualifier which would be:

javascript:"sys_idIN" + gs.getUser().getMyGroups()

No other scripting required 🙂

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thanks. I tried it this way and it gave me all of the groups, not just the ones i am a member of.