- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Many of the kinds of things y'all want to customize in Discovery (especially sensors and CI consolidation) involve some programming in JavaScript. Even if you're already familiar with JavaScript, you may run into something new when you look at our existing code for examples: object-oriented programming in JavaScript. Then on top of that, we've extended JavaScript a bit with a some things specific to Service-now.com.
There is lots of great material already available for object-oriented JavaScript. If you're seriously interested in becoming a JavaScript expert, I highly recommend JavaScript: the Definitive Guide, by David Flanagan. It's simply the best reference out there I've run into. Alternatively, here are some good starting points on the Intertubes: Douglas Crockford's excellent JavaScript essays, Mike Koss' text, and JavaScriptKit's tutorial.
But to learn about Service-now.com's extensions, read on...
You may already be familiar with script includes — but if not, navigate to Discovery Definition→Script Includes to see a list of them. If you drill into one (say, "DiscoveryStatus"), you'll see that it contains the JavaScript declaration of the DiscoveryStatus JavaScript class.
The key here is that the name of the script include matches (exactly) the name of the class declared within it. We've extended JavaScript to automagically include a script include whenever (a) a class is referenced that hasn't already been declared, and (b) there is a script include with exactly the same name as the class.
For example, suppose you write the following script to execute on the server:
function getStatusNumber(statusID) {
var myStatus = new DiscoveryStatus(statusID);
return myStatus.number;
}
Your script didn't define the DiscoveryStatus anywhere ... yet it would would run just fine. That's because our JavaScript extensions automagically include the DiscoveryStatus script include when your script references the DiscoveryStatus class (in the second line of the script above).
You can (and should!) use this feature yourself. There are just a few things to remember:
- This only works (of course!) for server-side scripts.
- Define your JavaScript classes in a script include, one class per script include.
- Name your script include exactly the same as your class' name (don't forget to match the upper and lower case letters).
This automagic JavaScript class inclusion from script includes works everywhere in our product, not just in Discovery.
That's all there is to it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.