Testing GlideAjax class from background script

Giri6
Tera Expert

If I have script include MyClass wich clicent callable with method  myFunction and if I pass  'sysparm_number' and 'sysparm_user', what is the code that I can put in background script to test? Appreciate it.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you need to check the value of the parameter

you can make the function as both client callable with sysparm_number or passing the function parameter

getIncidents: function(number1){

var number = JSUtil.nil(number1) ? this.getParameter('sysparm_number') : number1;

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you need to check the value of the parameter

you can make the function as both client callable with sysparm_number or passing the function parameter

getIncidents: function(number1){

var number = JSUtil.nil(number1) ? this.getParameter('sysparm_number') : number1;

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

asifnoor
Kilo Patron

Hi,

you can call your SI from bg like this

new MyClass().myFunction("1234","user");

and in your SI, you can use the code provided by Ankur and test it.

Let me know if you need any further assistance.

Giri6
Tera Expert

Thanks. Will test it. It would help without modifying  existing scripts as they don't have parameters declared in the function definition and code to assign properly.

But I really liked to have an option to test using snippet as mentioned by Ankur.

Hi Giri,

if you want to use same function to be called from client side using GlideAjax and also from server side then that approach is better instead of creating duplicate functions for same functionality.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader