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

servicenow-client

v1.0.7

Published

A Javascript client for ServiceNOW REST API.

Downloads

19

Readme

ServiceNOW-Client

A Javascript client for ServiceNOW REST API.

Installation

Run npm install servicenow-client to install the package.

Basic Usage

const servicenowClient = require('servicenow-client');

servicenowClient = new servicenowClient('https://<INSTANCE>.service-now.com','<USERNAME>','<PASSWORD>');

servicenowClient.getSingleRecord('<TABLE_NAME>', <SYS_ID>, (res)=>{
    console.log(res);
});

Supported Actions

//returns JSON of record
getSingleRecord('<TABLE_NAME>', '<SYS_ID>', callback);

//returns sys_id of created record
createRecord('<TABLE_NAME>', <JSON_RECORD_BODY>, callback);

//returns true if success, false otherwise
deleteSingleRecord('<TABLE_NAME>', '<SYS_ID_OF_RECORD_TO_BE_DELETED>', callback);

//returns sys_id of updated record
updateSingleRecord('<TABLE_NAME>', <JSON_RECORD_BODY> , '<SYS_ID_OF_RECORD_TO_BE_DELETED>', callback);

//Returns JSON of list of record(s). Use query builder for building advanced serviceNOW  encoded query
getRecords('<TABLE_NAME>', '<ENCODED_QUERY>', callback);

//returns count of records matching given query
getRecordCount('<TABLE_NAME>', '<ENCODED_QUERY>', callback);

Example Usage of Above Actions

servicenowClient.getSingleRecord('<TABLE_NAME>', '<SYS_ID>', (res) => {
    //use response
    console.log(res);
});

servicenowClient.createRecord('<TABLE_NAME>', {'endpoint': 'published'}, (res) => {
    //use response
    console.log(res);
});

servicenowClient.deleteSingleRecord('<TABLE_NAME>', '<SYS_ID>', (res) => {
    //use response
    console.log(res);
});

servicenowClient.updateSingleRecord('<TABLE_NAME>', <JSON_RECORD_BODY> ,'<SYS_ID>', (res) => {
    //use response
    console.log(res);
});

servicenowClient.getRecords('<TABLE_NAME>', '<ENCODED_QUERY>', (res) => { //Use query builder to create encoded query
    //use response
    console.log(res);
});

servicenowClient.getRecordCount('<TABLE_NAME>', '<ENCODED_QUERY>', (res) => { //Use query builder to create encoded query
        //use response
        console.log(res);
})

Query Builder Example Usage

var queryBuilder = new QueryBuilder();

//Less than '<'
var query = queryBuilder.field('sys_created_on').lessThan('2019-02-15 14:30:18');

//Less than using Date object
var query = queryBuilder.field('sys_created_on').lessThan(moment(new Date()).subtract(1, 'days').toDate());

//Greater than using Moment object
var query = queryBuilder.field('sys_created_on').lessThan(moment(new Date()).subtract(1, 'days'));


//compound query using and, lessThan, greaterThan
var query = queryBuilder.field('number').greaterThan('S').and().field('sys_created_on').lessThan(moment(new Date()).subtract(1, 'hours'));

//Between two dates (both date and moment objects supported), numbers, Strings 
var query = queryBuilder.field('sys_created_on').between('2015-02-15 14:30:18', '2019-02-18 14:30:18');
var query = queryBuilder.field('risk_score').between(47, 52);
var query = queryBuilder.field('number').between('A', 'Z');

//Empty String query
var query = queryBuilder.field('description').isEmptyString();

//Example of 'IN' operator
var query = queryBuilder.field('number').isOneOf(['INC0010122','INC0010120']);

//Is anything operator
var query = queryBuilder.field('number').isAnything();

//Contains operator
var query = queryBuilder.field('number').contains('<YOUR_STRING>');

//Order ascending/descending
var query = queryBuilder.field('number').contains('<YOUR_STRING>').or().contains('<OTHER_STRING>').orderAscending();

//Multiple conditions on a single field
var query = queryBuilder.field('number').contains('<YOUR_STRING>').and().contains('<OTHER_STRING>').orderDescending();

//Ends with operator
var query = queryBuilder.field('number').endsWith('<YOUR_STRING>');

//Does not contain
var query = queryBuilder.field('number').doesNotContain('<YOUR_STRING>');

//equals
var query = queryBuilder.field('number').equals('<YOUR_STRING>/<ARRAY>');

//isEmpty
var query = queryBuilder.field('number').isEmpty();

//isNotEmpty
var query = queryBuilder.field('number').isNotEmpty();