how to get groups in which user is member of using script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 10:36 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 11:18 PM
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'
};
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.