Skip to content

Instantly share code, notes, and snippets.

@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 / 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;

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 / Sys ID values on insert of new record.md
Last active October 11, 2018 22:25
Are all these values equal on different stages? Is it always so? What about getUniqueValue()?
var kb = new GlideRecord("kb_submission");
var sys_id_before_init = kb.sys_id;
// undefined
var sys_id_before_init = kb.getUniqueValue();
// null

kb.initialize();

var sys_id_after_initialize = kb.sys_id;

I come across this trick when a request is created from a call. Request is created and parent field is populated with call sys_id value.

var url = "catalog_home.do?sysparm_view=catalog_default&sysparm_processing_hint=setfield:request.parent=";
url += current.sys_id;

action.setRedirectURL(url);

Evaluate your scripts safely, 'cause safity is #1 priority.

var name = "Processor";

// var int_custom = eval("new SIName" + name + "(xml, ticket);");

var gc = GlideController;
gc.putGlobal('xml', xml);
gc.putGlobal('ticket', ticket);
@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 / 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()

GlideLabelUtil

Seen in

LabelsAjax (sys_script_include.do?sys_id=6232e3c10a0a0bb900e19499e162b36d)

Methods:

  • assign
  • assignLabel
  • getLabelEntries