getMyGroups gets parent groups as well
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2016 05:20 AM
Hi,
The built-in function getMyGroups also returns all parent groups of the groups that you are in.
To only return the specific groups that you are in, create a new script include like so:
Name: getMySpecificGroups
Client Callable: true
Script:
function getMySpecificGroups(){
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery("user", gs.getUserID());
gr.addQuery("group.active", true);
gr.query();
var array = [];
while (gr.next()) {
array.push(gr.getValue('group'));
}
return array;
}
You can then user this script from for example a module filter with a condition:
Assignment Group Is javascript:getMySpecificGroups()
Best Regards,
Miriam
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2017 02:07 PM
Hi Mariam - this does not seem to be working for me; whenever I try to add the script include in the filter area, it is showing "assignment group=(empty) as it is not recognizing the javascript:getMySpecificGroups. It seems to be thinking it is an invalid group name vs running the script. Do you know how to work around this? I do not want parent groups displaying as it clutters up people's work queues.
Thanks,
Diane

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2017 02:49 PM
Hi Diane,
Can you please in this way and see if it helps:
var getMySpecificGroups = Class.create();
getMySpecificGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroups : function(){
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery("user", gs.getUserID());
gr.addQuery("group.active", true);
gr.query();
var array = [];
while (gr.next()) {
array.push(gr.getValue('group'));
}
return array;
},
type: 'getMySpecificGroups'
});
In condition, please use below and see if this helps.
javascript:new getMySpecificGroups().getGroups()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2017 12:56 AM
Hi Diane,
Did you include the parentheses after?
javascript:getMySpecificGroups()
BR /Miriam