- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 09:28 AM
I have a variable in a variable set that shows all users by default and they do not want to change that, but on an order guide and the catalog items under that order guide, they want that user field to only show active users.
Script Include
var FilterUserResultstoActive = Class.create();
FilterUserResultstoActive.prototype = {
initialize: function() {},
activeUsers: function() {
var userCheck = new GlideRecord("sys_user");
userCheck.addEncodedQuery('active=true');
userCheck.query();
},
type: 'FilterUserResultstoActive'
};
And then onload client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('FilterUserResultstoActive');
ga.addParam('sysparm_name', 'FilterUserResultstoActive');
ga.getXML(FilterUserResultstoActive);
function FilterUserResultstoActive(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
}
}
But the filter isn't working. Any ideas on what I am missing?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 09:50 AM - edited 12-22-2023 10:02 AM
Also, you can create a Catalog Client Script for variable set - you can call your filter logics there, but still...you need your query on the variable itself - refQual - or find a way to pass it (using session or similar approach).
In my opinion this is not optional way to do it - reusing unusable set just for the idea of reusing and causing lots of work and possible undesired results afterwards.
On second thought you can use sys_class_name to decide if you should show all users or only active ones - you just add in the variable as reference qualifier your script include but a bit changed - check this for reference what i mean - https://servicenowguru.com/scripting/script-includes-scripting/advanced-reference-qualifier-script-i...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 09:47 AM
@JuliaHowells Instead of writing the client script, you should use a reference qualifier in this case. For more information please refer to https://docs.servicenow.com/bundle/vancouver-platform-administration/page/script/server-scripting/co...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 11:22 PM
Sharing this live example demo where I added a resuable class and made the AbastractAjaxProcessor become a base class to dynamically call parameters that can revceive any type of class, function and payload from the client towards the server side using GlideAjax.
Dynamic Script Include and GlideAjax in ServiceNow: Scalable & Reusable Code for Architects
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 06:26 PM
i created this full course about Script Include and Client Script using glideajax and how to build it the right way.