A Node.js client for the ServiceNOW REST API.
Run npm install servicemeow
to install the package.
const ServiceMeow = require('servicemeow');
const sm = new ServiceMeow('https://<INSTANCE>.service-now.com','<USERNAME>','<PASSWORD>');
const record = await sm.getSingleRecord('<TABLE_NAME>', <SYS_ID>);
// returns JSON of record
getSingleRecord('<TABLE_NAME>', '<SYS_ID>');
// returns sys_id of created record
createRecord('<TABLE_NAME>', { /* <JSON_RECORD_BODY> */ });
// returns true if success, false otherwise
deleteSingleRecord('<TABLE_NAME>', '<SYS_ID_OF_RECORD_TO_BE_DELETED>');
// returns sys_id of updated record
updateSingleRecord('<TABLE_NAME>', { /* <JSON_RECORD_BODY> */ }, '<SYS_ID_OF_RECORD_TO_BE_DELETED>');
// Returns JSON of list of record(s). Use query builder for building advanced serviceNOW encoded query
getRecords('<TABLE_NAME>', '<ENCODED_QUERY>');
// returns count of records matching given query
getRecordCount('<TABLE_NAME>', '<ENCODED_QUERY>');
const record = await sm.getSingleRecord('<TABLE_NAME>', '<SYS_ID>');
const id = await sm.createRecord('<TABLE_NAME>', {'endpoint': 'published'});
const deleted = await sm.deleteSingleRecord('<TABLE_NAME>', '<SYS_ID>');
const id = await servicenowClient.updateSingleRecord('<TABLE_NAME>', { /* <JSON_RECORD_BODY> */ }, '<SYS_ID>');
// Consider using QueryBuilder to create encoded queries
const records = await servicenowClient.getRecords('<TABLE_NAME>', '<ENCODED_QUERY>');
const count = await sm.getRecordCount('<TABLE_NAME>', '<ENCODED_QUERY>');
const { QueryBuilder } = require('servicemeow');
const queryBuilder = new QueryBuilder();
// Less than '<'
const query = queryBuilder.field('sys_created_on').lessThan('2019-02-15 14:30:18');
// Less than using Date object
const query = queryBuilder.field('sys_created_on').lessThan(new Date());
// Greater than using Date object
const query = queryBuilder.field('sys_created_on').lessThan(new Date());
// compound query using and, lessThan, greaterThan
const query = queryBuilder.field('number').greaterThan('S').and().field('sys_created_on').lessThan(new Date());
// Between two dates, numbers, Strings
const query = queryBuilder.field('sys_created_on').between('2015-02-15 14:30:18', '2019-02-18 14:30:18');
const query = queryBuilder.field('risk_score').between(47, 52);
const query = queryBuilder.field('number').between('A', 'Z');
// Empty String query
const query = queryBuilder.field('description').isEmptyString();
// Example of 'IN' operator
const query = queryBuilder.field('number').isOneOf(['INC0010122','INC0010120']);
// Example of 'NOT IN' operator
const query = queryBuilder.field('foo').isNoneOf(['bar', 'baz']);
// Is anything operator
const query = queryBuilder.field('number').isAnything();
// Contains operator
const query = queryBuilder.field('number').contains('<YOUR_STRING>');
// Order ascending/descending
const query = queryBuilder.field('number').contains('<YOUR_STRING>').or().contains('<OTHER_STRING>').orderAscending();
// Multiple conditions on a single field
const query = queryBuilder.field('number').contains('<YOUR_STRING>').and().contains('<OTHER_STRING>').orderDescending();
// Ends with operator
const query = queryBuilder.field('number').endsWith('<YOUR_STRING>');
// Does not contain
const query = queryBuilder.field('number').doesNotContain('<YOUR_STRING>');
// equals
const query = queryBuilder.field('number').equals('<YOUR_STRING>/<ARRAY>');
// isEmpty
const query = queryBuilder.field('number').isEmpty();
// isNotEmpty
const query = queryBuilder.field('number').isNotEmpty();
// Example of 'SAMEAS' operator
const query = queryBuilder.field('left').isSameAs('middle');
// Example of 'NSAMEAS' operator
const query = queryBuilder.field('left').isNotSameAs('right');
// Example of 'GT_FIELD' operator
const query = queryBuilder.field('foo').greaterThanField('bar');
// Example of 'GT_OR_EQUALS_FIELD' operator
const query = queryBuilder.field('foo').greaterThanOrEqualsField('bar');
// Example of 'LT_FIELD' operator
const query = queryBuilder.field('foo').lessThanField('bar');
// Example of 'LT_OR_EQUALS_FIELD' operator
const query = queryBuilder.field('foo').lessThanOrEqualsField('bar');
// Example of 'RELATIVEGT' operator
const query = queryBuilder.field('sys_updated_on').since(1, 'hour');
// Example of 'RELATIVELT' operator
const query = queryBuilder.field('sys_updated_on').notSince(10, 'minute');
// Example of 'MORETHAN' operator
const query = queryBuilder.field('sys_created_on').isMoreThan(1, 'year').before('sys_updated_on');
// Example of 'LESSTHAN' operator
const query = queryBuilder.field('sys_created_on').isLessThan(12, 'hour').before('sys_updated_on');
Typings are automatically generated from the JSDoc comments prior to npm publish. As such, declaration files are included in the npm package distribution but not committed to git.
ServiceMeow was forked from ServiceNOW-Client
by
Kaushal Shah.