This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
showSimpleLoadingMessage('Retrieving data'); | |
var arrListElements = slowFunctionThatReturnsAnArrayOfStrings() || ['Element 1', 'Element 2', 'Element 3']; | |
var flyoutListHTML = getHTMLListFromArray( | |
arrListElements, | |
'disc', | |
'Element: ' | |
); | |
g_form.clearMessages(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gaSlowGlideAjaxCall = new GlideAjax('{some_glideajax_script_include'); | |
//todo: Set the second argument to the method you want to execute from your GlideAjax Script Include | |
gaSlowGlideAjaxCall.addParam('sysparm_name', '{some_slow_glideajax_script_method'); | |
//todo: Add whatever other GlideAjax parameters you need to add below, such as: | |
gaSlowGlideAjaxCall.addParam('record_sys_id', g_form.getUniqueValue()); | |
gaSlowGlideAjaxCall.addParam('some_field_value', g_form.getValue('{field_name}')); | |
//Show animated form message: "Processing request..." | |
//This will continue to show and animate until we call stopAnimatedLoadingFieldMessage(), | |
// which we'll do in the callback function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gaSlowGlideAjaxCall = new GlideAjax('{some_glideajax_script_include'); | |
//todo: Set the second argument to the method you want to execute from your GlideAjax Script Include | |
gaSlowGlideAjaxCall.addParam('sysparm_name', '{some_slow_glideajax_script_method'); | |
//todo: Add whatever other GlideAjax parameters you need to add below, such as: | |
gaSlowGlideAjaxCall.addParam('record_sys_id', g_form.getUniqueValue()); | |
//Show animated form message: "Processing request..." | |
//This will continue to show and animate until we call g_form.clearMessages(), | |
// which we'll do in the callback function | |
//todo: Update message from "Processing request" to whatever is appropriate to your situation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var grAttachment = new GlideRecord('sys_attachment'); //the table where attachment metadata is stored | |
grAttachment.get('0003ea666f015600623008efae3ee4f7'); //sys_id of a record in the sys_attachment table | |
var md5HashSum = calculateMD5Hash(grAttachment); | |
function calculateMD5Hash(attachmentGR) { | |
var attachmentInputStream = GlideSysAttachmentInputStream(attachmentGR.sys_id + ''); | |
var chksum = (new GlideChecksum()).calculateMD5CheckSum(attachmentInputStream); | |
gs.print(chksum); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GlideSysAttachment.copy("ZZ_YYtable_name", "default_image_sys_id_here", "ZZ_YYtable_name", current.getValue('sys_id')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |