I need to test a part of code which is in client script.

EKTA2
Tera Expert

Hi. I have a GlideAjax function within a client script. I need to test it, without having to replicate all the stuff via UI or browser. How can I test it? I couldn't figure a way for  testing it via background script. 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@EKTA2 

you can use javascript executor for this to call that glideAjax

Using the Javascript Executor to test client scripts 

You can be on that form from where GlideAjax has to be initiated and then press Alt+Ctrl+Shift+j

It opens up a executor and you can access form values using g_form object and then invoke GlideAjax, write your code and Run the code

Something like this

AnkurBawiskar_0-1736413442203.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

4 REPLIES 4

Juhi Poddar
Kilo Patron

Hello @EKTA2 

  • You can define the required inputs as variables and replicate the function logic in a background script.
  • Since background script and the Script Include both execute on the server side, there should be no issues testing the logic in this way.

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

Runjay Patel
Giga Sage

Hi @EKTA2 ,

 

Whats the issue ? your GA is written in client script so it will get invoked once form load or onchange. you can check the behavior on form.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Ankur Bawiskar
Tera Patron
Tera Patron

@EKTA2 

you can use javascript executor for this to call that glideAjax

Using the Javascript Executor to test client scripts 

You can be on that form from where GlideAjax has to be initiated and then press Alt+Ctrl+Shift+j

It opens up a executor and you can access form values using g_form object and then invoke GlideAjax, write your code and Run the code

Something like this

AnkurBawiskar_0-1736413442203.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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