logo

NJP

JavaScript Tips and Tricks: JSUtil...

Import · Feb 11, 2010 · article

imageDid you know that your Service-now instance comes complete with a handy-dandy set of commonly used JavaScript utility methods? These are in a script include named "JSUtil", and you can easily use its methods in your scripts.For example, there's a method named "nil()" (along with "notNil()" that lets you easily test whether a value is null, undefined, or an empty string. You might use it in your own code it like this:

function myFunc(val) { if (JSUtil.nil(val)) return null; return 'My prefix: ' + val;}

That's all there is to it! Take a look at the script include to see what's in it — all the methods are documented. And if you think of another method that ought to be in there, please add a comment describing what you'd like to see...

View original source

https://www.servicenow.com/community/in-other-news/javascript-tips-and-tricks-jsutil/ba-p/2288148