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-rest

v1.2.2

Published

Comprehensive wrapper for ServiceNow REST APIs: Table, Aggregate, ImportSet, Attachment

Downloads

13

Readme

ServiceNow REST

Comprehensive wrapper for the ServiceNow REST API's

Promise based

Contact [email protected] for any questions, feedback, issues, or feature requests.

Update 5/29/2016: Major revisions to GlideRecord and Attachment API Update 1/27/2016: Added clone method to GlideRecord

Update 1/26/2016: v1 Release

Update 1/21/2016: GlideRecord is fully functional Built out skeleton of other REST APIs

Table of contents

Install

npm install servicenow-rest

GlideRecord

var GlideRecord = require('servicenow-rest').gliderecord;

var gr = new GlideRecord('instance','tablename','user','password','v1')

Version is optional

query

//methods options
gr.setReturnFields('number,short_description');
gr.addEncodedQuery('active=true');
gr.setLimit(10);

gr.query().then(function(result){ //returns promise
	console.log(result)
})

get


gr.get('sysid').then(function(result){
	//your code
}).catch(error) {
	//errors
})

insert

var obj = {
	short_description:"Production Server down",
	description:"latin words here",
	priority:1
};
gr.insert(obj).then(function(response){
	//your code
}).catch(error) {
	//errors
})

update

var obj = {
	comment:"hey whats up"
}
gr.update('sysid',obj).then(function(response){
	//your code
}).catch(error) {
	//errors
})

clone

//two parameters
//sysid of record you want to clone
//array fields that you want to clone
var arr1 = ['short_description','description']
gr.clone('sysid',arr1).then(function(value) {
	console.log(value);
})

addProxy

If proxy requires credentials they need to be embedded in the URL

gr.addProxy('https://user:[email protected]');

delete


gr.get('sysid').then(function(response){
	//your code
}).catch(error) {
	//errors
})

GlideAggregate

var GlideAggregate = require('servicenow-rest').glideaggregate;

query

gr.addEncodedQuery('encodedquery')
gr.addAggregate('agg','fieldname') //agg options: MIN,MAX,SUM,AVG
gr.groupBy('fieldname')
gr.addHaving('sum','impact','>',1) // Aggregate,fieldname,operator,value
gr.addCount(int) //integer
gr.orderByDescending() // Automatically sorts by ascending

gr.query().then(function(value) {
	console.log(value);
})

ImportSet

Create records on import set tables that are immediately transformed

var ImportSet = require('servicenow-rest').importset;

var gr = new ImportSet('instance','tablename','user','password') //tablename should be the import table here

get

gr.get(sysid).then(function(value) { console.log(value); }

insert

gr.get(

Attachment

var Attachment = require('servicenow-rest').attachment;

var gr = new Attachment('instance','tablename','user','password')

get

gr.get(sysid).then(function(value) {
	console.log(value);
})

delete

gr.delete(sysid).then(function(value) {
	console.log(value);
})

getAttachment

gr.getAttachment(sysid).then(function(value) {
	console.log(value)
})

getAttachments

gr.getAttachments(tablename,sysid,dir)
    .then(function(value) {
        console.log(value); //value is an array of file names attached
    })

attachFile

gr.attachFile(tablename, sysid,file,dir).then(function(value) {
    console.log(value);
});

##About Promises##

A promise is an alternative to callback hell. It's pretty simple

gr.query() //This right here returns a 'promise'
	.then(function(value) {
	//code when successful
	},function(error) {
		code when failed
	}) //resolve and reject are functions with one argument. When the request succeeds, the resolve function is called. When it fails, the reject function is called

//alternative
gr.query().then(function(value) {

}).catch(function(error) {
	/error code here
})

##Questions and Issues## For feature requests and bug reports please use the github issue tracker. For immediate support join the ServiceNow Slack Community (get an auto-invite here: http://snowslack.io) or email [email protected]

##Authors## Abey Ahmad. Contributors Welcome