Skip to content

Instantly share code, notes, and snippets.

@thisnameissoclever
thisnameissoclever / sn_animated_progress_collapsible_message.js
Last active May 29, 2024 12:22
ServiceNow Animated Progress Message with Collapsible Details
/**
* Show an animated loading message such as "Loading...", where the dots will be
* animated with the interval specified in msInterval; first showing "Loading.", then
* "Loading..", then "Loading...", up to the number of dots indicated in maxDots.
* Once maxDots is reached, the message will be reset to "Loading." and the animation
* will repeat until stopAnimatedLoadingMessage() is called.
*
* @param {String} fieldName - The name of the field on which to show the loading message.
* @param {String} messageText - The loading message to be shown, which will be followed
* by animated dots (or whatever character is specified in dotChar, if specified).
@denniskupec
denniskupec / gm_requests.js
Created October 28, 2017 06:21
GM_xmlhttpRequest + GM_download => Promises
// GM_download
function Download(url, name, opt={}) {
Object.assign(opt, { url, name })
return new Promise((resolve, reject) => {
opt.onerror = reject
opt.onload = resolve
GM_download(opt)
})
@Tusko
Tusko / jquery.ajax.js
Last active November 12, 2021 02:54
$.ajax Promise
/*
* ajax Defaults (optional):
$.ajaxSetup({
type : 'POST',
dataType : 'json',
cache : true,
global : true,
data : {},
contentType : 'application/json',
beforeSend : function (xhr) {
@jnerius
jnerius / OAuthGitHubHandler.js
Last active November 18, 2022 19:16
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;
@jnerius
jnerius / OAuthBitlyHandler.js
Last active February 28, 2021 19:21
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);
},
@jnerius
jnerius / servicenow_restmessagev2_response_as_attachment.js
Last active June 28, 2023 03:59
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);
@jmbauguess
jmbauguess / CopyARequest.js
Last active August 25, 2022 09:30
Back end functionality to copy variables from one requested item to another
/**
* @description Allows users to copy a requested item on the form
* @extends {AbstractAjaxProcessor}
* @type {Class}
*/
var CopyARequest = Class.create();
CopyARequest.prototype = Object.extendsObject(AbstractAjaxProcessor, {
/**
* @description ServiceNow's ArrayUtil
* @type {ArrayUtil}
@ryanhoskin
ryanhoskin / PAGERDUTY_V6.xml
Last active May 11, 2019 21:15
ServiceNow Update Set for PagerDuty integration
<?xml version="1.0" encoding="UTF-8"?>
<unload unload_date="2015-01-30 16:06:32">
<sys_remote_update_set action="INSERT_OR_UPDATE">
<collisions/>
<commit_date/>
<deleted/>
<description>PagerDuty is a third-party system used to alerts individuals/teams when an important issue requires attention. The integration with ServiceNow focuses on finding an owner (assignee) for high priority incidents.
Integration is supported in both directions allowing incidents to be acknowledged, delegated (assigned to another group) and resolved in either system. The following work models are supported:
1. User uses PagerDuty for notification only. Once notified, he/she uses ServiceNow to assign, investigate, resolve the incident.
@chrisjhoughton
chrisjhoughton / wait-el.js
Last active April 17, 2025 08:14
Wait for an element to exist on the page with jQuery
var waitForEl = function(selector, callback) {
if (jQuery(selector).length) {
callback();
} else {
setTimeout(function() {
waitForEl(selector, callback);
}, 100);
}
};