npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

service-now

v1.0.1

Published

Service Now JSONv2 API wrapper. Includes easy to use functions to perform common tasks. Formerly published as 'snow-query'

Downloads

17

Readme

ServiceNow v1.0

Service Now JSONv2 API wrapper. Includes easy to use functions to perform common tasks. Formerly published as 'snow-query'.

Highlight Features:

  • Querying tables (GET),
  • Updating Records (POST),
  • Specialized Classes and Methods for common tasks (i.e. Closing RITMs.).

SNOW JSONv2 API Reference:

1. Getting Started

Get ServiceNow now!
npm install service-now --save
Require, and Initiate
'use strict'
const ServiceNow = require('service-now');
var Snow  = new ServiceNow('https://<your-instance-name>.service-now.com/', yourUsername, yourPassword);

2. GET and POST - How to Query and Update Records (Class: Snow)

getRecords

A streamlined method to set your table and query then retrieving records.

Note: by default query Object contains "displayVariables: true". Each record's primary key will be converted to their proper value.

Snow.getRecords(queryObject,callback)

Code Example:

Snow.getRecords({
    table: 'sc_req_item',
    query: {
        number:'RITM0123456'
        }
    },(err,data) => {
    // Do Stuff Here.
});
setTable

Sets the table variable for your Snow instance.

Snow.setTable(Table)    // Table as String

Code Example:

Snow.setTable('sc_req_item');
setQuery

Sets the query variable for your Snow instance.

Snow.setQuery(Arguments[Object], DisplayVariables, DisplayValues)

Code Example:

Snow.setQuery({
    active: true,
    number: 'RITM0123456',
    }, 'true', 'false');
get

Gets records from using the variables set from the setTable and setQuery methods.

Snow.get(callback)

Code Example:

Snow.get((err,data) => {
    // Do Stuff Here.
});
post

Updates records using the variables set from the setTable and setQuery methods. This will update all records matching the query.

Snow.post(JSONbody[object], callback)

Code Example:

Snow.post({
    close_notes: 'Batch closing tickets from ServiceNow.',
    active: false
    }, (err, res) => {
    // Do stuff with updated records.
    }
);

3. RITM Methods (Class: Snow.Ritm)

getRitms

Gets RITMs matching the queryObject passed to the function.

Snow.Ritm.getRitms(queryObject, callback)

Code Example:

Snow.Ritm.getRitms({active: true, assignment_group: ''},(err,data) => {
    // Do Stuff Here.
});
getActive

Gets all active RITMs.

Snow.Ritm.getActive(callback)

Code Example:

Snow.Ritm.getActive((err,data) => {
    // Do Stuff Here.
});
getByNumber

Gets a single RITM by number.

Snow.Ritm.getByNumber(Number, callback)

Code Example:

Snow.Ritm.getByNumber('RITM0123456',(err,data) => {
    // Do Stuff Here.
});
closeByNumber

Closes a single RITM by number.

Snow.Ritm.closeByNumber(Number, CloseNotes, callback)

Code Example:

Snow.Ritm.closeByNumber('RITM0123456', 'Closing the ticket, issue was resolved.',(err,data) => {
    // Do Stuff Here.
});

4. User Methods (Class: Snow.User)

getUsers

Gets all users in your SNOW instance.

Snow.User.getUsers(callback)

Code Example:

Snow.User.getUsers((err,data) => {
    // Do Stuff Here.
});
getUserGroups

Gets all user groups in your SNOW instance.

Snow.User.getUserGroups(callback)

Code Example:

Snow.User.getUserGroups((err,data) => {
    // Do Stuff Here.
});
getUserByUserName

Gets a single user by their username in your SNOW instance.

Snow.User.getUserByUserName(username, callback)

Code Example:

Snow.User.getUserByUserName('JSmith', (err,data) => {
    // Do Stuff Here.
});
getUserById

Gets a single user by their sys_id in your SNOW instance.

Snow.User.getUserById(userId, callback)

Code Example:

Snow.User.getUserByUserName('007c75ce6f2c9100222a57ee2c3ee43d', (err,data) => {
    // Do Stuff Here.
});

5. Category Methods (Class: Snow.Category)

getCategories

Gets all categories in your SNOW instance.

Snow.Category.getCategories(callback)

Code Example:

Snow.Category.getCategories((err,data) => {
    // Do Stuff Here.
});
getCategoryItems

Gets all category items in your SNOW instance.

Snow.Category.getCategoryItems(callback)

Code Example:

Snow.Category.getCategoryItems((err,data) => {
    // Do Stuff Here.
});

6. Utility Methods (Class: Snow.Utilities)

groupBy

Groups an array of JSON documents by a specific oject property.

Snow.Utilities.groupBy(data, property, callback)

Code Example:

Snow.Ritm.getActive((err, data) => {
    Snow.Utilities.groupBy(data, 'cat_item', groupData => {
        // Do Stuff Here
    });
});
flattenVariables

Note: Only for use with RITM documents when querying the same cat_item. Refactors the embedded variables document, to be included in the parent document.

Snow.Utilities.flattenVariables(data, callback)

Code Example:

Snow.Ritm.getActive((err, data) => {
    Snow.Utilities.flattenVariables(data, flatData => {
        // Do Stuff Here
    });
});

Script Examples

Query Records Script Example 1

This is the preferred method of querying records.

'use strict'
const ServiceNow = require('service-now');
var Snow  = new ServiceNow('https://<your-instance-name>.service-now.com/', yourUsername, yourPassword);

Snow.getRecords({
    table: 'sc_req_item',
    query: {
        number:'RITM0123456'
        }
    },(err,data) => {
    // Do Stuff Here.
});
Query Records Script Example 2

This is an alternative method of querying records.

'use strict'
const ServiceNow = require('service-now');
var Snow  = new ServiceNow('https://<your-instance-name>.service-now.com/', yourUsername, yourPassword);

// Input whatever table you like.
Snow.setTable('sc_req_item');

// Declare your query object, and the 'displayvariables' & 'displayvalues' boolean as a string. By default it is true.
// Snow.setQuery(QueryObject, DisplayVariables, DisplayValues);
Snow.setQuery({
    active: true,
    number: 'RITM0123456',
    }, 'true', 'false');

// Get your data and do stuff.
Snow.get((err,data) => {
    // Do Stuff Here.
});
Update Records Script Example 2

This is an example method of updating records.

'use strict'
const ServiceNow = require('service-now');
var Snow  = new ServiceNow('https://<your-instance-name>.service-now.com/', yourUsername, yourPassword);

// Set your table.
Snow.setTable('sc_req_item');

// Set your query.
Snow.setQuery({
    active:true,
    priority: 3
    }, 'true', 'true');

// In this example we close all the tickets matching our query.
Snow.post({
    close_notes: 'Batch closing tickets from ServiceNow.',
    active: false
    }, (err, res) => {
    // Do stuff with updated records.
    }
);
License

The MIT License (MIT)

Copyright (c) 2016 Elias Hussary

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.