Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unable to Call script include in filter condition

Ganesh Palve
Tera Expert

PFB Script include

 

var Test = Class.create();
Test.prototype = {
    initialize: function() {
    },

	ApprovalNotCome : function (){
	var arr =[];
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('roles=approver_user');
gr.query();
while (gr.next()) {
    var gr1 = new GlideRecord('sysapproval_approver');
    gr1.addQuery('approver.name', gr.getValue('name'));
    gr1.query();
    if (!gr1.next()) {
        arr.push(gr.getValue('name'));
    }
}
gs.log("my error - "+arr);
   return arr;
},

    type: 'Test'
};

 

 

and I am calling above script include like below - javascript: new global.Test().ApprovalNotCome();

GaneshPalve_0-1726756122825.png

but not able to get values in filter?? please help here 

Thank in advance

1 ACCEPTED SOLUTION

Hi @Sid_Takali ,

Got the the solution I just made Sandbox enabled to True on script include and then able to see records

GaneshPalve_0-1726761819884.png

 

View solution in original post

7 REPLIES 7

Thanks so much! Your solution worked perfectly for me. Really appreciate you taking the time to share your knowledge with the community! 💌

d_17
Tera Expert

Hi @Ganesh Palve 

Try running this in background script. 

    var arr =[];
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('roles=approver_user');
gr.query();
while (gr.next()) {
    var gr1 = new GlideRecord('sysapproval_approver');
    gr1.addQuery('approver.name', gr.getValue('name'));
    gr1.query();
    if (!gr1.next()) {
        arr.push(gr.getValue('name'));
    }
}
gs.print("my error - "+arr);

Check if you getting any names when you run it? I ran on my instance and i am getting value 

Bert_c1
Kilo Patron

@Ganesh Palve 

 

I verified your script include works and that it is not called when used in the filter condition you posted on the sys_user table.

 

I suggest you read:

 

https://docs.servicenow.com/bundle/xanadu-platform-user-interface/page/use/using-lists/concept/c_Fil...

 

and find a Filter type that works for your case.