Skip to content

Instantly share code, notes, and snippets.

View thisnameissoclever's full-sized avatar

Tim Woodruff thisnameissoclever

View GitHub Profile
@thisnameissoclever
thisnameissoclever / add object to object.js
Last active January 23, 2022 00:14
Add one object/array to another, avoiding "pass-by-reference" pitfalls in JavaScript.
/**
* Adds one object to another, nesting the child object into the parent.
* this is to get around javascript's immutable handling of objects.
* @param name {String} - The name of the property of the parent object, in which to nest the child object. <br />For example, if the name parameter is set to "pickles" then "parent.pickles" will return the child object.
* @param child {Object} - The object that should be nested within the parent object.
* @param [parent={}] {Object} - The parent object in which to nest the child object. If the parent object is not specified, then the child object is simple nested into an otherwise empty object, which is then returned.
* @returns {Object} - A new object consisting of the parent (or an otherwise empty object) with the child object nested within it.
* @example
* //sets myNewObject to a copy of originalObject, which now also contains the original (yet un-linked) version of itself as a child, under the property name "original"
* var myNewObject = addObjToObj("orig
@thisnameissoclever
thisnameissoclever / ServiceNow Client Script-Get URI Param.js
Created May 13, 2017 06:06
This ServiceNow Client Script returns an object consisting of a property for each URI parameter, and its' value.
/**
* Get the values of each URI param as properties of an object (name-value pairs).
* @param url
* @returns {{}}
* @example - In the URL www.google.com/page?urip=pickles&otheruriparam=bananas, you could use getAllUrlParams().urip to get "pickles".
*/
function getAllUrlParams(url) {
// get query string from url (optional) or window
var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
@thisnameissoclever
thisnameissoclever / Client Script-Open GlideOverlay Window to Submit or Update Another Record.js
Created May 13, 2017 06:20
ServiceNow Client Script GlideOverlay: Open GlideOverlay Window to Submit or Update Another Record.js
// opens a new u_error_reporting record from an sc_task record
function openOverlay(overlayID, overlayTitle, iframeURI, height, width) {
// Instantiate the GlideOverlay
// Note: GlideOverlay extends GlideBox, which contains the close() method
var overlayWindow = new GlideOverlay({
id: overlayID,
title: overlayTitle,
iframe: iframeURI,
allowOverflowX: true,
closeOnEscape: true,
var ClientTimeZoneUtils = Class.create();
ClientTimeZoneUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCurrentTimeInTimeZone: function() {
var tz = this.getParameter('sysparm_tz');
var tzu = new TimeZoneUtils();
var gdt = tzu.setTimeZone(tz);
return gdt.getDisplayValue();
},
@thisnameissoclever
thisnameissoclever / Deploy sub-prod config (background script).js
Last active January 23, 2022 00:14
ServiceNow - Deploy sub-prod configuration automatically
function deployDevConfig() {
_deactivateAllNonAdmins();
_disableEmails();
_setHeaderName();
_deactivateLDAPServers();
}
function _deactivateAllNonAdmins() {
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('roles!=admin');
@thisnameissoclever
thisnameissoclever / getMethodsAndProperties.js
Last active November 22, 2023 09:48
ServiceNow: Get Methods and Properties of an object
var methodsAndProperties = [];
var testObj = new GlideFilter('a=b', 'rule'); //TODO: replace this with whatever object you want to test
getMethodsAndProperties(methodsAndProperties, testObj);
gs.print('\n' + methodsAndProperties.join('\n'));
/**
* Populates an extant array in-place, of methods and properties of a given object.
* @param methodsAndProperties {array} - the array to populate/modify in-place.
@thisnameissoclever
thisnameissoclever / Documentation & Article
Last active March 20, 2018 01:24
ServiceNow "Try in Portal" button
https://snprotips.com/blog/2018/3/15/service-catalog-try-in-portal-button
@thisnameissoclever
thisnameissoclever / JournalRedactor.js
Last active April 6, 2024 08:28
Redact or delete a given journal entry in ServiceNow. Usage documentation: http://redactor.snc.guru/
/*
Script Include definition:
Name: JournalRedactor
Client Callable: false
Accessible from: All application scopes
Additional details:
Version: 1.3
Usage documentation: http://redactor.snc.guru/
License: https://gist.github.com/thisnameissoclever/767b8a738b929a0bd943965431061c1e
*/
/***CLASSES***/
class APIClass {
/**
* An APIClass object
* @param name {string} The name of the API class
*/
constructor(name, classDesc = '') {
this._className = name;
this._classDescription = classDesc;
/**
@thisnameissoclever
thisnameissoclever / DynamicRefQuals.js
Last active January 23, 2022 00:13
DynamicRefQuals (Client-callable Script Include)
var DynamicRefQuals= Class.create();
DynamicRefQuals.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//Client-callable
/*
To quickly and easily create a dynamic reference qualifier script, simply add a custom method to this Script Include.
Here are the guidelines for modifying this Script Include:
1. In the "@author" JSDoc tag of the method your implement, please put your user ID (For example: "twoodruff").
2. See how the getGroupMembersByID and getGroupMembersByName methods are documented, and try to document your method in the same fashion.
3. Unless you've got permission from the author, please do not modify anyone else's methods.