Using script includes in sysparm_fixed_query

lzeke
Giga Contributor

Is this possible? Can anyone point my to an example?

I assume the script include needs to be client callable and I would need to call this through GlideAjax, but I would need to set the function name, the parameters, etc., while it seems that only thing I can do in a sysparm_fixed_query is to specify an expression.

Thanks a lot!

1 ACCEPTED SOLUTION

lzeke
Giga Contributor

Actually, I made it work in both environments: there was nothing wrong with the code, the problem was with the


sysparm_fixed_query - the type of the field was a Reference, not a String, and my test function was returning a string. This - somehow - caused SN to abort the the method call.




Thanks for your help, Cory!


View solution in original post

7 REPLIES 7

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Laszlo,



You would treat a fixed query link any other query param. Here are a couple of examples:


        &sysparm_fixed_query=opened_by=javascript:gs.getUserID()


        &sysparm_fixed_query=sys_idINjavascript:new MyInclude().getSysIds()^active=true



You just make a regular script include. It doesn't need to be client-callable, nor have anything to do with GlideAjax. You set the fixed query in the URL of the list you are opening.


Thanks, Cory, this is what I thought as well.



But on Eureka, when I try to call my AopHelper class' test() method by:



&sysparm_fixed_query=u_officer.u_supervisor=javascript:new AopHelper().test()



this is what I get in my sys log:



org.mozilla.javascript.EcmaError: "AopHelper" is not defined.


Caused by error in <refname> at line 1



==> 1: new AopHelper().test()




when I make AopHelper client-callable, I don't get this warning, but still doesn't work.




Any clue what's going on?


coryseering
ServiceNow Employee
ServiceNow Employee

I was wrong-the script include does have to be client callable to work in a query param.


What does the method return? Does it return a value if you call it directly in Scripts - Background? Are there any errors in the log when try to load a page with the filter and it is client callable?


Thanks, Cory, for following up on this.



Here is the code of the test() method:



test: function()


{


gs.log("AopHelper.test method is called");


return "supervisor1";


}



If call this from a before-query business rule:



var s = new AopHelper().test();


gs.log("Value of s=" + s);



it works flawless, I see in the system log both


the "AopHelper.test method is called" message and the "Value of s=supervisor1" message.



So, this method is OK in a before-query business rule, but doesn't work in a query param. What can fix this?