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

This got it! My mistake was not having the return after the while loop and as you said must let the query know which column I'm filtering so I was missing the 'nameIN' portion. Thank you all for your help!

AbhishekGardade
Giga Sage

Hello Chad,

This thread will help you to solve your issue:

https://www.servicenowguru.com/scripting/script-includes-scripting/advanced-reference-qualifier-scri...

Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

Check out this code:

function CNDTCheckRestrictedStatus()
{

var gp = '';
var assignment=[];
var restricted = current.u_restricted;

//return if the current restriction status

gs.log("restricted: "+restricted);

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()) {

gp += (',' + grp.group);

assignment.push(groups.getValue('name'));
gs.log("DP: RefQual: " + gp);
return 'sys_idIN' + gp;
}
}

Thank you,
Abhishek Gardade

Chad R
Tera Expert

Just realized now I need to figure out in the if restricted = false segment how to make it not return groups that have been disabled. 🙂 wasn't thinking about that.