Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Advanced Reference Qualifier for Assignment Groups

Chad R
Tera Expert

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. 

find_real_file.png

 

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;
		}
	}
1 ACCEPTED SOLUTION

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Elijah Aromola
Mega Sage

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();
    }
}

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.

 

 

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;
}

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader