- 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 10:25 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 09:53 AM
Hello Chad,
This thread will help you to solve your issue:
Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 10:06 AM
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;
}
}
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 10:39 AM
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.