How to test a piece of javascript quickly?

Lei Wang3
Giga Expert

How to test a piece of javascript quickly? 

Do you have to test it in client ui policy or business rule? fix script? which is quick and convenient? for example, to query GlideRecord?

 

1 ACCEPTED SOLUTION

Javascript Executor is only for client-side code, and you shouldn't use GlideRecord in client-side code.

If you are just trying to test the js executor, try this simple line

alert("Hello from the Javascript Executor");

 

To learn more about scripting, I highly recommend this

https://developer.servicenow.com/dev.do#!/learn/courses/tokyo/app_store_learnv2_scripting_tokyo_scri...

 

and 

https://www.youtube.com/watch?v=62Nabpb94Jw

View solution in original post

12 REPLIES 12

that works, thanks!

can I save background script to rerun it again? right now, after running one time, it only gives a history link

No problem!

If you want to save a server side script to run it on demand, you can create a fix script

https://docs.servicenow.com/bundle/tokyo-application-development/page/build/applications/task/t_Crea...

If you want to save the script and rerun it, fix script is the best.

For client side execute script in javascript executor.


Raghav
MVP 2023

from the javascript execute, I tried to run the following code. but looks like nothing happens after clicking run. anything wrong with my code?

LeiWang3_0-1670085702782.png

 

var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.query();

while(gr.next()) {
alert('Incident count: ' + gr.getRowCount());
}

This is because you are trying to run server side code in javascript executor, you need to run client code here.


Raghav
MVP 2023