Unable to run Script Include from sys_user_group_types table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 07:43 AM
Hi All,
My org is setting up report views as a way for end users to see their own and related teams task items.
To do this we've set up a dashboard with a filter that allows them to display based on group types. The problem is the script include isn't working.
Checking the work in the Scripts - Background with a gs.log, I do see the SysIDs of the group types. But when running the same script include from the Group Types table I get 0 results.
Any ideas about the script or possibly a business rule?
function Test() {
var myID = gs.getUserID();
var myIDString = myID.toString();
var grpTypeList=[];
var gr = new GlideRecord("sys_user_grmember");
gr.addEncodedQuery("user=" + myIDString + "^group.typeISNOTEMPTY");
gr.query();
var i=0;
while(gr.next()) {
grpTypeList.push(gr.group.type);
}
return grpTypeList;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 07:08 PM
Try with the following script.
function Test() {
var myID = gs.getUserID();
var myIDString = myID.toString();
var grpTypeList=[];
var gr = new GlideRecord("sys_user_grmember");
gr.addEncodedQuery("user=" + myIDString + "^group.typeISNOTEMPTY");
gr.query();
var i=0;
while(gr.next()) {
grpTypeList.push(gr.group.type);
}
return grpTypeList.toString();
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 07:42 PM
you are calling it in wrong manner
SysId [IS ONE OF] javascript: Test();
I assume your report is on table "sys_user_group_type"
Update script include as this and it should be client callable. make the script include classless
function Test() {
var myID = gs.getUserID();
var grpTypeList = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addEncodedQuery("user=" + myID + "^group.typeISNOTEMPTY");
gr.query();
while (gr.next()) {
grpTypeList.push(gr.group.type.toString());
}
return grpTypeList.toString();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2025 12:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2025 11:43 AM
There's a business rule that stops the script from running for non-itil users, I don't know which one it is.
My workaround was to add "gr.setWorkflow(false);" (see below) to get the script include to work.