ServiceNow JavaScript API Libraries

This ServiceNow JavaScript API library was adapted from something that Garrett Griffin put together in 2014. I found the libraries so useful, that I decided to build upon, add to, and update them throughout the last several years (with permission from Garrett) in order to make developing ServiceNow-centric code in my local IDE a lot easier. While I've done a lot of work on this over the last few years, most of the credit must surely go to Garrett for his hard work in starting this out. Thanks, Garrett!

Follow me on Twitter (@TheTimWoodruff) to get notified of major updates to the libraries, so you’ll know when to pull down the updates!

Github repo

Adding Libraries


The IDE that I use is Jetbrains Webstorm, which makes this whole process a lot easier. To add a custom library in Webstorm, make sure you’ve pulled down the git repo and know where it’s located. Once that’s done, go to File > Settings > Languages & Frameworks > JavaScript > Libraries, then click Add.

In the Add dialog, enter a name like “sn-js-lib”, then click the “+” icon to the right, click “Attach directories”, select the folder you downloaded the libraries to, and click OK a couple of times, then you’re all set!

Visual Studio Code

Visual Studio Code's Intellisense feature is compatible with the ES6 folder of this repo. Here are the steps to setting it up in your local workspace.

1. Clone the repo
Clone the repository to your local machine

2. Copy the ES6 folder to your local Servicenow Workspace
You can copy and rename the folder if you like. It just needs to be visible in your workspace when you are running Visual Studio Code.

3. Create your jsconfig.json file
In the your local ServiceNow workspace folder, create a file called jsconfig.json. You can add whatever options you'd like to your configuration, but make sure that the ES6 folder you copied and your workspace files are included in your project either implicitly or explicitly via the jsconfig file.



In this example, because the include property is not specified, it will include all files, directories, and subdirectories below where the jsconfig.json file is located. This example also sets the target version of javascript to es5, because that is what ServiceNow uses on the server.

If you want to explicitly include your files in your jsconfig.json, you can do so using the include option documented here. If you do so, make sure to include both the ES6 folder, and your own project files.

4. You are good to go!
After setting up all the correct files, you should be good to go. Open your workspace in Visual Studio Code and you should enjoy Intellisense suggestions for ServiceNow libraries!

Undocumented APIs

It’s important to be aware that the mechanism I used to pull in a lot of these APIs, exposed undocumented APIs as well (especially in the ES5 version - ES6 not so much, that’s a work in progress).
Use these undocumented APIs at your own risk. If you don’t understand how an API works, don’t use it. Look up the API docs before using an unknown API.