Script Include and Client Script using glideajax

JuliaHowells
Tera Expert

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? 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

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...

View solution in original post

7 REPLIES 7

Sandeep Rajput
Tera Patron
Tera Patron

@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...

BillMartin
Mega Sage

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

 

BillMartin
Mega Sage

i created this full course about Script Include and Client Script using glideajax and how to build it the right way.