Skip to content

Instantly share code, notes, and snippets.

@icerge
icerge / patterns.md
Last active April 16, 2021 14:53
Development and configuration patterns in ServiceNow
View patterns.md

Ajax calls from Native forms and Catalog items

Client script + UI Script + Script Include (Ajax) + Script Include (API)

Client script is a calling side. Optionally, it may be wrapped into a UI Script to form re-usable Client side API.

Script Include (Ajax) is an interface for client side interactions it fetches parameters, validate them and call necessary APIs.

Script Include (API) implements server side functionalities that may and most probably will be used by both Client and Server side logic. No Ajax parameters are available in context, they are supplied as method arguments.

Naming convention

@icerge
icerge / get URL parameters.md
Last active December 2, 2022 15:15
Server side story of how to get URL parameters
View get URL parameters.md

gs.action

gs.action.getGlideURI().get('parameter_name');

Another longer alternative:

gs.action.getGlideURI().getMap().get('sysparm_query');
@icerge
icerge / code reviews agains HS and BP.md
Last active March 26, 2021 13:57
Notes made from HS issues review. Collection of object misuses or interesting observations.
View code reviews agains HS and BP.md

Global UI Scripts

It is an eval from BP perspective and HS doesn't like it either.

I found two basic mistakes in configurations.

As Source file for JS Include

You put a shared code or a 3rd party lib to UI Script and include it to a widget. Global checkbox is redundant. Any UI Script will be loaded.

As shared lib for form client side scripts

Yea, good motivation, avoid code duplication. Any shared functionality can be put to UI script and loaded in client side

@icerge
icerge / idea.md
Created November 4, 2020 13:41
ServiceNow - Approval types
View idea.md

Approval types

Requirement justification

We had a very similar requirement due to the multiple number of different approvals needed for our Change process to be able to display an Approval Type to our approvals. We were able to accomplish this by performing the following configurations:

Technical design

  1. Add a column to the Approval table [sysapproval_approval]. For our solution we simply added a Choice type column called Approval Type [u_type]. We then created the choices we needed in the Choices related list.
  2. Next we modified the Workflow Activity Definitions for each of the Approval Workflow Activities. You can find these by searching for Workflow Activity Definitions in the navigator. For example, open the Approval - User definition record. Scroll down to the Activity Variables tab and click the New button to add a new variable. This will seem very familiar if you have created Catalog variables. For our solution our variable was created with the following attributes:
  • Column name = u_appr
@icerge
icerge / number_of_rows_removed.md
Last active November 17, 2021 16:58
Security: ACLs, Query Business Rules
View number_of_rows_removed.md

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.

@icerge
icerge / confirm onSubmit.md
Last active December 19, 2020 06:27
Using modal windows in SN: GlideModal, confirm onSubmit
View confirm onSubmit.md

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 / administrating.md
Last active April 20, 2021 14:55
Collection of admin tools and features
View administrating.md

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 / email_display.md
Created January 2, 2019 12:05
Enrich Send/Receive Email posts of Activity log
View email_display.md

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.

View glide_label.md

GlideLabelUtil

Seen in

LabelsAjax (sys_script_include.do?sys_id=6232e3c10a0a0bb900e19499e162b36d)

Methods:

  • assign
  • assignLabel
  • getLabelEntries
@icerge
icerge / rest_api_import_set.md
Last active January 18, 2022 18:09
REST API things
View rest_api_import_set.md

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!