- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 09:42 AM
Hi All,
My first post! I'm working on a Advanced reference qualifier that calls a script include based on a custom field on our incident form called u_restricted. The goal is if that is flagged true on the ticket then the reference qualifier that calls the script include will query a list of assignment groups that are for restricted tickets they also have the u_restricted field. Below is the code I have thus far and its failing dismally hoping some of your more well versed admins can lend me a hand. I'm about a year into my ServiceNow adventure so still learning the ropes. Appreciate any help!
Here is my dictionary override with the reference qualifier segment.
Here is the Script Include code:
function CNDTCheckRestrictedStatus()
{
var assignment=[];
var restricted = current.u_restricted;
//return if the current restriction status
if(restricted == false)
return;
var groups = new GlideRecord('sys_user_group');
groups.addQuery('u_restricted', '=', 'true');
groups.addQuery('active', '=', 'true');
groups.query();
//query groups to return if the ticket is restricted
while(groups.next()) {
assignment.push(groups.getValue('name'));
gs.log("DP: RefQual: " + assignment);
return assignment;
}
}
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 10:09 AM
Hi Chad,
update code as below; you need to have the return statement after the while loop ends
also in reference qualifier script update this; you need to let the query know which column the script include function is returning so accordingly it will filter the records
function CNDTCheckRestrictedStatus()
{
var assignment=[];
var restricted = current.u_restricted;
//return if the current restriction status
if(restricted == false)
return;
var groups = new GlideRecord('sys_user_group');
groups.addQuery('u_restricted', '=', 'true');
groups.addQuery('active', '=', 'true');
groups.query();
//query groups to return if the ticket is restricted
while(groups.next()) {
assignment.push(groups.getValue('name'));
}
return 'nameIN' + assignment;
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 09:49 AM
Your code needs to resolve to a comma separated string like "group1, group2, group3", etc. Try the following:
function CNDTCheckRestrictedStatus() {
var assignment = [];
var restricted = current.u_restricted;
//return if the current restriction status
if (restricted == false)
return;
var groups = new GlideRecord('sys_user_group');
groups.addQuery('u_restricted', '=', 'true');
groups.addQuery('active', '=', 'true');
groups.query();
//query groups to return if the ticket is restricted
while (groups.next()) {
assignment.push(groups.sys_id);
return assignment.toString();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 10:01 AM
Hi Elijah,
Thanks for the response I gave your script a try and got the following error in my logs:
Invalid query detected, please check logs for details [Unknown field null in table sys_user_group]
The subsequent logs are not much use.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 10:07 AM
Try this modification:
function CNDTCheckRestrictedStatus() {
var assignment = [];
var restricted = current.u_restricted;
if (restricted == false)
return;
var groups = new GlideRecord('sys_user_group');
groups.addEncodedQuery('u_restricted=true^active=true');
groups.query();
while (groups.next()) {
assignment.push(groups.sys_id);
}
return 'sys_idIN' + assignment;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 10:09 AM
Hi Chad,
update code as below; you need to have the return statement after the while loop ends
also in reference qualifier script update this; you need to let the query know which column the script include function is returning so accordingly it will filter the records
function CNDTCheckRestrictedStatus()
{
var assignment=[];
var restricted = current.u_restricted;
//return if the current restriction status
if(restricted == false)
return;
var groups = new GlideRecord('sys_user_group');
groups.addQuery('u_restricted', '=', 'true');
groups.addQuery('active', '=', 'true');
groups.query();
//query groups to return if the ticket is restricted
while(groups.next()) {
assignment.push(groups.getValue('name'));
}
return 'nameIN' + assignment;
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader