Reference Variable to show the filter

Vamshi_ch123
Tera Contributor

Hi All,

 

I have a variable in my variable set caller ID and this variable set is used in multiple record producers , but for 1 specific record producer I want to apply a filter to the caller ID reference variable to show the list of users based on Job level

for this I have written a onload client script and client callable script include but still it's not working

 

Client script:

function onLoad() {
    var userVariableName = 'caller_id';

    var ga = new GlideAjax('getcallerBasedonJobLevel');
    ga.addParam('sysparm_name', 'callerDetails');

    // Get the response from the Script Include
    ga.getXMLAnswer(function(response) {
        var filter = response;
       
        g_form.setFilter(userVariableName, filter);
    });
}
 
Script Include:
var getcallerBasedonJobLevel = Class.create();
getcallerBasedonJobLevel.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    callerDetails: function() {
        var userids = [];

        var gr = new GlideRecord("sys_user");
        gr.addQuery("active", "true");
        gr.addEncodedQuery("u_job_level=F1^ORu_job_level=F2");
        gr.query();

        while (gr.next()) {
            userids.push(gr.sys_id.toString());
        }

        if (userids.length > 0) {
            return "sys_idIN" + userids.join(',');
        } else {
            return ""; // Return an empty filter if no users found
        }
    },

    type: 'getcallerBasedonJobLevel'
});
 
Thank you
1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@Vamshi_ch123 You will not be able to set the filter of Reference field from the client script. You need to use an Advanced reference qualifier on the reference field for this purpose. For more information on the advanced reference qualifier, please refer to https://docs.servicenow.com/bundle/xanadu-platform-administration/page/script/server-scripting/conce....