Skip to content

Instantly share code, notes, and snippets.

View thisnameissoclever's full-sized avatar

Tim Woodruff thisnameissoclever

View GitHub Profile
var MSTeamsMessage = Class.create();
MSTeamsMessage.prototype = {
/**
*
* @param {string} [teamsEndpoint=gs.getProperty()] - The MS Teams endpoint for the channel you're trying to post a message to.
* You can also specify this later by calling the .setEndpoint() method.
*/
initialize : function (teamsEndpoint) {
//local init
data.orgChart = data.orgChart || {};
data.orgChart.tiers = data.orgChart.tiers || [];
data.orgChart.i18n = {
avatar: gs.getMessage("{0} avatar"),
directReport: gs.getMessage("{0} direct report"),
directReports: gs.getMessage("{0} direct reports"),
minimumCharacters: gs.getMessage("Please enter {0} or more characters")
};
var loopDetected = false;
@thisnameissoclever
thisnameissoclever / LICENSE.txt
Created April 7, 2021 15:19
This license applies to all public gists on https://gist.github.com/thisnameissoclever
MIT License
Copyright (c) 2017 Timothy Woodruff
https://snprotips.com/
This license applies to all public gists on https://gist.github.com/thisnameissoclever
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@thisnameissoclever
thisnameissoclever / BenchmarkRunner.js
Last active October 13, 2022 17:04
ServiceNow Benchmark Runner Script Include
var BenchmarkRunner = Class.create();
BenchmarkRunner.prototype = {
initialize : function () {
this.timers = {};
},
/**
* Execute two functions with the specified arguments, and get info about which was faster
* (and by how much).
*
@thisnameissoclever
thisnameissoclever / Populate default value for image field.js
Created May 31, 2022 15:41
Populate default value for image field ServiceNow
GlideSysAttachment.copy("ZZ_YYtable_name", "default_image_sys_id_here", "ZZ_YYtable_name", current.getValue('sys_id'));
@thisnameissoclever
thisnameissoclever / Display form in dialog.js
Created May 31, 2022 15:44
Display form in dialog in ServiceNow and pre-populate some fields
function showMyForm(){
var recordID = g_form.getUniqueValue() || "-1";
var recordTableName = g_form.getTableName();
var dialog = new GlideDialogForm('Update Record', recordTableName);
//Set to "-1" to show new record form instead
dialog.setSysID(recordID);
//If false, will show related lists as well.
dialog.addParm('sysparm_form_only', 'true');
//todo: Form view?
@thisnameissoclever
thisnameissoclever / Expanding infomessage.js
Created May 31, 2022 15:46
Expanding infomessage with functional components in ServiceNow
var message = '';
message += 'This is an expanding info message. It can even run code! Click "Show more" to see!';
message += '<div>';
message += '<p><a href="#" onclick="javascript: jQuery(this.parentNode).next().toggle(200);">Show more</a></p>';
message += '<div style="display: none;">';
message += '<ul style="list-style: none">';
message += '<li>This is the expanded info in the message.</li>';
message += '<li>You can include any details you like here, including info retreived from a script like the sys_id of the current record: ' + g_form.getUniqueValue() + '</li>';
message += '</ul>';
@thisnameissoclever
thisnameissoclever / getJournalEntries.js
Last active April 6, 2024 08:28
Get ServiceNow Journal Entries, optionally parse and convert HTML control-characters and line-breaks, and return an array of the last N journal entries.
/**
* Get the journal entries from a given record, and optionally parse and convert line breaks and
* HTML and wokkas (< and >) to HTML (<br />\n and HTML-ized character codes).
* @param {GlideRecord} current - A GlideRecord object positioned to the record you want to get the
* journal entries from.
* @param {String} journalFieldName - The journal field name (e.g. "work_notes", "comments",
* "comments_and_work_notes", etc.).
* @param {Boolean} [convertLineBreaksToHTML=false] - Set this to true, to convert line-breaks
* (\r\n) to HTML (<br />\n).
* @param {Boolean} [convertWokkasToHTML=false] - Set this to true, to convert wokkas ("<" and ">")
@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).