Skip to content

Instantly share code, notes, and snippets.

View nancystodd's full-sized avatar

Nancy S Todd nancystodd

View GitHub Profile
@nancystodd
nancystodd / servicenow-scripting.md
Created October 24, 2019 00:40 — forked from animyeboah/servicenow-scripting.md
ServiceNow Developer Best Practices

GlideRecord

  • Use getUniqueValue to get sys_id.
  • Use newRecord instead of instantiating to get a new record with default values.
  • Dot-walking on GlideRecord returns GlideElement, use getRefRecord to get GlideRecord.

GlideForm

  • Use getBooleanValue for boolean fields.
@nancystodd
nancystodd / debugging_cheatsheet.md
Created October 25, 2019 23:59 — forked from iamwill/debugging_cheatsheet.md
Debugging on the Glide Platform

Debugging tips and tricks

Platform Troubleshooting

Console output too chatty?
Set com.glide.util.Log.developer_filter = true to cut down on non-interactive console log entries such as scheduled workers. (Don't forget to remove it when you're done!)

Utility urls

Note: Fast! These don't need a database.

ServiceNow UI Developer cheat sheet


Utility URLs

URL Purpose
/stats.do Quick stats
/threads.do View active threads
@nancystodd
nancystodd / JSUtil2.js
Created December 20, 2019 18:21 — forked from abhididdigi/JSUtil2.js
This is the entire JSUtil2 script. Creating a gist, to show it on Service Now diary.com
/*
* JSUtil already has some utility functions, Some more utility functions.
* Written by diddigiabhi@gmail.com
* Re-written for Service Now from underscore.js: http://underscorejs.org/
*
*/
var JSUtil2 = Class.create();

GlideRecord & GlideAggregate Cheat Sheet ❗

GlideRecord(String tableName) ❗

var gr = new GlideRecord('incident'); // use the incident table
gr.query(); // fetch data from the database
while (gr.next()) { // advance
    gs.info(gr.short_description);
}
@nancystodd
nancystodd / gr_props_values
Last active April 24, 2020 19:04
Glide Record Print all Properties and Values Example
// This is just a handy snippet I use when troubleshooting glide records
// in a background script to quickly see all the properties and values of a glide record
// Just change the table name and query for the glide record to test
var gr = new GlideRecord("<your_table_name>");
gr.addQuery("<field_name>", "<value>");
gr.query();
while (gr.next()) {
for (var prop in gr ){
@nancystodd
nancystodd / gist:f61041a4355276ef8798095d2fca2202
Created April 25, 2020 16:09
ServiceNow --None-- values for choice lists
The -- None -- option may not have a sys_choice record associated with it.
A choice list field set to -- None -- evaluates to these values, depending on the script context as listed below.
For client-side scripts,such as client scripts: "" (empty string)
For server-side scripts, such as business rules: "0" (string of the number zero)
function (someString) {
// test string is opened with curly brace or machine bracket
if (someString.trim().search(/^(\[|\{){1}/) > -1) {
try { // it is, so now let's see if its valid JSON
var myJson = JSON.parse(someString);
// yep, we're working with valid JSON
} catch (e) {
// nope, we got what we thought was JSON, it isn't; let's handle it.
}
} else {
@nancystodd
nancystodd / sn-glide-field.txt
Last active February 5, 2023 21:17
Make ServiceNow Glide Object Visible
var fieldTypes = new GlideRecord('sys_glide_object');
fieldTypes.addQuery('sys_id', 'IN', ['sys_id_1', 'sys_id_2']);
fieldTypes.setValue('visible', true);
fieldTypes.updateMultiple();

ServiceNow - Jelly scripting cheatsheet

UI Page consists of jelly, client script and processing script. UI Macro has the jelly script only (but client script can be injected in jelly script) Usages:

  • Open as a page using URI https://<instance_name>.service-now/<ui_page_name>.do
  • Open as a modal using client script (UI action, client script, etc) (see snippet 1)
// Snippet 1
var gm = new GlideModal('UI_dialog_name');
gm.setTitle('Show title');