How do I filter a Reference variable based on the user having a role in a field in the referred list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2018 02:54 PM
I have a table that presents categories in a reference variable; allowing the user to select one before submitting an incident
Let’s say I have the 7 categories listed below.
Category Active Role
Audio true AV
CD Reader false
Laptop true
Network true
Printer true Support
Server true
Video true AV
Of those 7 categories, I’d only like to display those where active = true. Easy enough, I could just create a reference qualifier condition of Active = true.
But what I would like to do is to have all users see those active categories with a null role, and only those who have the role to see the records with a role that matches them
So, if a user that has either no role, or only itil role assigned, they will see the following categories available to choose from (i.e. those categories with no role which are active):
Laptop
Network
Server
However, if a user with the AV role logs on, they will see the following categories available (those categories with no role which are active + those active roles with the AV role):
Audio
Laptop
Network
Server
Video
I have taken a look writing a reference qualifier, but I am confused as to how I would bring back all of the records where the role matches one of the user’s roles.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2018 10:54 AM
I've found that returning sys_ids can be slow - if your table might get long, then I would handle it by passing back a filter instead. If the role is referencing the same roles that are assigned to users, then I would do an advanced reference qualifier to call a script include:
javascript:new MyCats().filterCats()
Script include:
var MyCats = Class.create();
MyCats.prototype = Object.extendsObject(AbstractAjaxProcessor, {
filterCats: function(){
var user = gs.getUser();
var roles = user.getRoles();
var rStr = roles.toString();
var filter = 'u_roleISEMPTY';
var rArr = rStr.split(',');
for(var i=0;i<rArr.length;i++){
filter += '^ORu_role.name=' + rArr[i];
}
return filter;
},
type: 'MyCats'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2018 09:40 AM
I created a script include that looks like the screenshot below. I called it from varialble's reference qualifier in the second screenshot. I get the error that is listed in the third screenshot. Evidently, there is something that I'm doing wrong. I don't know if it's in the script, or where I call the function from the variable's reference qualifier.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2018 01:28 PM
Reference qualifier - you don't need the 'new'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 08:07 AM
The ref qualifier needs to be adjusted:
javascript:new MyCats().filterCats()
It's missing the first set of parentheses.