Skip to content

Instantly share code, notes, and snippets.

View thisnameissoclever's full-sized avatar

Tim Woodruff thisnameissoclever

View GitHub Profile
@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 / 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');
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 / 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,
@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 / 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