Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / rest_api_import_set.md
Last active December 6, 2023 11:52
REST API things

Import Set API

Custom response

For any good reason I need to get more things in my Import Set response for REST interface. Ok, I just go to Transform map, use Explicit script, that script right in the transform map record, type there:

response.custom_element = "Welcome, REST response extension!";

and enJoy the Rest of the day! :)

Note, credits go to SN community. Stay brave!

GlideLabelUtil

Seen in

LabelsAjax (sys_script_include.do?sys_id=6232e3c10a0a0bb900e19499e162b36d)

Methods:

  • assign
  • assignLabel
  • getLabelEntries
@icerge
icerge / email_display.md
Created January 2, 2019 12:05
Enrich Send/Receive Email posts of Activity log

Use case

I'd like to reply to an email recieved in a ticket... right from the activity log.

Sample idea - Render reply/reply all buttons

Add UI controls to Activity formatter

It's actually a processor - EmailDisplay. Locate function writeBody and construct output HTML sample before it is printed.

@icerge
icerge / administrating.md
Last active April 20, 2021 14:55
Collection of admin tools and features

Column aliases

ServiceNow maintains a table of field-column name mappings: sys_storage_alias. It is especially useful when reviewing list of indexes available in a table like cmdb_ci_storage_device. Index definition may include a storage alias instead of human-readable name of the field.

For example, cmdb_ci_storage_device.computer field has a storage alias a_ref_3.

Reason for alias use is probably related to the way table structure is organized. Alias (most probably) won't be used if table is stand-alone. If table is part of hierarchy and table-per-hierarchy or table-per-partition extension models are used, then column with the same names will to be mapped to aliases. E.g. cmdb_os_user.computer and cmdb_ci_storage_device.computer have computer and a_ref_3 aliases.

What do we know about variables?

@icerge
icerge / confirm onSubmit.md
Last active April 17, 2024 12:35
Using modal windows in SN: GlideModal, confirm onSubmit

get confirmation in onSubmit client script

Have you ever got into this trap?

I'd like to make a confirmation with user that he/she are certain about submit/save/update action using a client script. This is the case. I can use a dumb confirm dialog which isn't cute at all. I can also try to use a GlideModal overlay with rich UI Page content. Why not?!

Well, because of

  • the fact that submit action has been already initiated from onSubmit function of Client Script perspective
  • and
@icerge
icerge / number_of_rows_removed.md
Last active November 17, 2021 16:58
Security: ACLs, Query Business Rules

Number of rows removed due to security constraint

User gets this message in a list of records whenever there is a record user doesn't have rights to view. I.e. there is an ACL restricting access to a record or there in NO ACL granting the access. Let's ignore security mode setting here.

It's a default system beharior.

Would you like to get rid of it? System to count with records user has access to?

Solution 1

Replicate row level read access ACLs to query business rules. Naturally, every query will get controlled.