Skip to content

Instantly share code, notes, and snippets.

@icerge
icerge / glidemultiple*_samples.md
Last active April 16, 2021 13:29
Glide Multiple operations (Update, Delete)

GlideMultipleUpdate usage

var x = new GlideMultipleUpdate('sys_user');
x.addQuery('company', "59a8f78c37561304985d8ff1b3990e2f");
x.setValue('company', "d4287b0c37561304985d8ff1b3990e92");
x.setValue('department', null);
x.execute();
@icerge
icerge / features_unsorted.md
Last active March 27, 2023 22:23
Unsorted features of ServiceNow

Workflow column renderer

/column_renderer_list.do It is based on ui_macro.

Ajax - request source

...
this.getParameter('x-referer');

The value is a URL the request is coming from.

@icerge
icerge / Workflow features.md
Last active October 11, 2018 21:51
Different unsorted workflow features and notices

task.wf_activity

OOTB there is a relationship between a task and a workflow activity creating the task. This is a reference to the activity instance. Note, it is inactive in dictionary, thus it can't be selected in filter builder etc. Although, this fact brings extra (unwanted) food for thoughts.

Additionally, wf_activity is a reference to workflow activity instance. Instance of activity which is used in the workflow. Be careful here, if you tie a rule based on activity id, you'll get it changed after the workflow version is changed.

Subflow activity

It ends up with system (internal) results only e.g. success if activity was successful. Return activity sets a parent workflow scratchpad. An extra activity is required to analyze the result of the subflow execution.

@icerge
icerge / scheduling in runtime.md
Last active October 11, 2018 21:55
Scheduling a script run in run-time

Pattern: I'd like something to happen in future.

It's a subset of the patter I'd like some event to happen in future. It covers the case of conditional execution: event + script action.

In the sample below I'd like to send reminder email (of course, if it is still valid).

var x = new ScheduleOnce();
x.setDocument(current);
x.setLabel("Approval reminder " + current.getDisplayValue());
x.setTime(/*now + 4 days*/);
@icerge
icerge / stop_watch.md
Last active July 24, 2023 11:11
Timer in SN - GlideStopWatch

Watch out performance of your queries!

var sw = new GlideStopWatch();  
var recGR = new GlideRecord('cmdb_ci');  
recGR.addQuery('sys_class_name', 'INSTANCEOF', 'cmdb_ci_server');  
recGR.addQuery('name', 'ABCDEF');  
recGR.setLimit(1);  
recGR.query();  
if (recGR.hasNext()) { 
@icerge
icerge / Unsuccessful GlideRecord operation.md
Last active January 2, 2019 10:49
Unsuccessful GlideRecord operations: failed insert, failed update, failed delete.

I used to believe my operations are successful. Well, it's not a bullet proof.

var x = new GlideRecord('incident');
var sys_id = x.insert();

sys_id;
// GUID 

x.isActionAborted()

well, there is a nice book, listing many Jelly features. Although, I don't know if it is mentioned there

Goal - validate form field values Alert message is get using 1 phase JAXL expression, JS: - prefix

function validateForm() {
 if (gel('first_name').value == '') {
  alert("${JS:gs.getMessage('Please input First Name')}");
 return false;
@icerge
icerge / Get Email Thread-Topic.md
Last active October 11, 2018 22:05
Sample code to get Thread-Topic header (email conversation topic) from inbound email.

Thread-Topic is a header of email message, it contains the original subject of the conversation

var headers = email.headers + "";
var topic_regex = /Thread-Topic:(.*)/i;
var topic_match = topic_regex.exec(headers);
var topic = (topic_match && topic_match[1]) ? topic_match[1] : email.subject;
@icerge
icerge / GlideController.md
Last active October 11, 2018 22:40
Observation of GlideController object

There is a class GlideController. It's not documented. However you have definitly come across it. In client-callable script include, for example. Or in OOTB code :)

class
close
enforceSecurity
enforcingSecurity
equals
evaluate
evaluateAsObject
evaluateGeneratedString
@icerge
icerge / get URLs.md
Last active March 28, 2023 12:41
Interesting ways to get URL to a record

Collection of methods to get URL to a record.

/*
Use GlideSubstituteURL class
.generateURL(GlideRecord, Record ID)
*/
var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());