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.

How to use try catch in ServiceNow Scripts

andymcdonald
Kilo Guru

I attended Steve Bell's advanced GlideRecord session at K16 and I believe there was an incidental comment made about how to properly implement exception handling in SN scripts.   However, I made no note of it and cannot remember exactly what the instructions were.   I believe there was something said about a property that needed to be set...

Anybody who knows the answer to this, please let me know.

As it is now, try catch is ignored and the script just dies.

6 REPLIES 6

Paul Curwen
Giga Sage

If it helps, the K16 Lab documentation mentioned can be found here:



Advanced GlideRecord Scripting (repeat 1 of 2)



Advanced GlideRecord Scripting (repeat 2 of 2)



Some really useful guidance in these.


***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

on this blast from the past, I can say my main issue was a lack of understanding on exactly what causes errors to be thrown in js.   Here's a nice reference I found:



Exceptional Exception Handling in JavaScript — SitePoint