Skip to content

Instantly share code, notes, and snippets.

@jmaxwell81
jmaxwell81 / EXAMPLE - Querying Incident table from client-side script.js ServiceNow EfficientGlideRecord: A MUCH more efficient and performant client-side GlideRecord queries, as efficient as GlideAjax (or more!)
//Client-side example usage
doThing();
function doThing() {
new EfficientGlideRecord('incident')
.setLimit(10)
.addNotNullQuery('assignment_group')
.addField('number')
.addField('short_description')
.addField('assignment_group', true) //Get display value as well
@jmaxwell81
jmaxwell81 / servicenow_restmessagev2_response_as_attachment.js
Created June 28, 2023 03:59 — forked from jnerius/servicenow_restmessagev2_response_as_attachment.js
Saving a RESTMessageV2 response as an attachment and getting the attachment's sys_id #ServiceNowSnippet
// This is where we'll save the attachment
var tablename = 'incident';
var recordSysId = '8d6353eac0a8016400d8a125ca14fc1f';
var filename = 'snlogo.png';
// Let's download the ServiceNow Logo
var logoUrl = 'https://instance.service-now.com/images/logos/logo_service-now.png';
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('get');
request.setEndpoint(logoUrl);
@jmaxwell81
jmaxwell81 / JSONtoGlide.js
Created May 2, 2022 19:24 — forked from jmbauguess/JSONtoGlide.js
Converts a GlideRecord object into JSON, or converts JSON into a GlideRecord. See http://sensibleservicenow.com/?p=49
/**
* @description Converts between JSON Objects and GlideRecords
* @namespace
* @type {Class}
*/
var JSONtoGlide = Class.create();
JSONtoGlide.prototype = {
/**
* @description Converts an object into a new GlideRecord
* @param {Object} json A json object
@jmaxwell81
jmaxwell81 / staticNowMetaTypesMap.ts
Created May 2, 2022 18:55 — forked from chaorace/staticNowMetaTypesMap.ts
The table/directory mapping used by the Service Now VSCode extension
export const StaticNowMap: IStaticNowMap = {
// Scriptable files
"SysNamesMap": {
"Data Model": {
"Relationships": "sys_relationship"
},
"Forms & UI": {
"Schedule Pages": "cmn_schedule_page",
"Styles": "sys_ui_style",
"Map Pages": "cmn_map_page",
@jmaxwell81
jmaxwell81 / get URLs.md
Created February 27, 2020 16:04 — forked from icerge/get URLs.md
Interesting ways to get URL to a record

Collection of methods to get URL to a record.

/*
Use GlideSubstituteURL class
.generateURL(GlideRecord, Record ID)
*/
var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
@jmaxwell81
jmaxwell81 / OAuthGitHubHandler.js
Created May 31, 2019 18:20 — forked from jnerius/OAuthGitHubHandler.js
ServiceNow OAuth Handler Script Include for processing OAuth Responses from GitHub
var OAuthGitHubHandler = Class.create();
OAuthGitHubHandler.prototype = Object.extendsObject(OAuthUtil, {
// Override postprocessAccessToken method. GitHub returns a urlencoded
// body, so we need to break this apart and extract the values.
postprocessAccessToken: function(accessTokenResponse) {
var contentType = accessTokenResponse.getContentType();
var contentBody = accessTokenResponse.getBody();
var paramMap = accessTokenResponse.getparameters();
var params = contentBody.split('&');
var parts;
@jmaxwell81
jmaxwell81 / OAuthBitlyHandler.js
Created May 31, 2019 18:20 — forked from jnerius/OAuthBitlyHandler.js
ServiceNow OAuth Handler Script Include for processing Bit.ly OAuth Tokens
var OAuthBitlyHandler = Class.create();
OAuthBitlyHandler.prototype = Object.extendsObject(OAuthUtil, {
initialize: function() {
},
interceptRequestParameters : function(requestParamMap) {
// Add/Modify request parameters if needed
this.preprocessAccessToken(requestParamMap);
},
@jmaxwell81
jmaxwell81 / AttachmentImportProcessor.js
Created January 20, 2019 05:38 — forked from johncaruso/AttachmentImportProcessor.js
Service Now Email Attachment Processor.Allows ServiceNow to accept attachments via email and process them through a data source/import set/ transform map.
/*
* Script include to process multiple attachments in an email through OOB Data Source process.
* Attaches to existing data source, dynamically creates a schedule import entry and runs.
* Processes attachments synchronously to prevent issues with multiple attachments
*
* Source: Fruition Partners
* Author: [email protected]
* Author: [email protected]
*/
/*
Given:
AD Groups: group(members)
|
|_a(1)
| |_b(2,3)
| | |_c(4)
| |_d(2,5)
@jmaxwell81
jmaxwell81 / fixTrackInUpdateSets.js
Created January 20, 2019 05:35 — forked from johncaruso/fixTrackInUpdateSets.js
Fixes issues when using "Track in Update Sets" UI action on custom scoped app table.
/**
* Fixes issues when using "Track in Update Sets" UI action on custom scoped app table.
*
* Per https://community.servicenow.com/community?id=community_question&sys_id=760fb629db58dbc01dcaf3231f9619bd
* a temporary table with a prefix of rep$x_ may be added to your app scope.
*
* As of Kingston, table columns get created in app scope but the table does not.
*
* @param {string} tableName
*/