Skip to content

Instantly share code, notes, and snippets.

@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 / User preference changes.md
Last active July 21, 2022 08:41
Changing User preferences (language, timezone)

There is a business rule - Change Own Profile - sys_script.do?sys_id=e1d271450a0a0b440098a39d7d36903e It reflects the following user profile changes to user session:

  • Language
  • Timezone
  • Time format
  • Date format It runs if user changes own profile. The script uses API which isn't documented though. The interesting thing is that language session changes doesn't apply through session API calls.
@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());
@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 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 / 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()
@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()) {