Skip to content

Instantly share code, notes, and snippets.

@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 / patterns.md
Last active April 12, 2024 02:47
Development and configuration patterns in ServiceNow

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 / 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!

@icerge
icerge / get URL parameters.md
Last active December 6, 2023 11:40
Server side story of how to get URL parameters

gs.action

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

Another longer alternative:

gs.action.getGlideURI().getMap().get('sysparm_query');
@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 / 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 / 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 / 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 / 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.

@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?