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 get groups in which user is member of using script include

Sanket Pawar
Tera Contributor

Hi All,

I have a from where we have 2 fields 

1. access type (dropdown ) - choice  as access_removal

2.groups (list colelctor) -configured on sys_user_group table.

 

if the choice is  selected as access_removal, then the groups field should show the groups in which user is member of.

how can i achive this using script include.

1 REPLY 1

Nayan  Dhamane
Kilo Sage

Hello @Sanket Pawar 

Please use the below script in reference qualifier:

 

javascript:if(current.variables.var1 == ‘acess_control’)new ScriptIncludeName().functioNameName();

And also use the below script in script include to check if the user is part of which group

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'
};
If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.