ServiceNow

ACL: understanding Advanced flag

When editing an ACL record there is a flag “Advanced” Wrong opinion: setting Advanced flag to false deactivates execution of script (field “Script”). Correct information: Advanced flag only controls visibility of the Script field. There could be some code in the “Script” field that you don’t see, but it will be still executed.

Search through all code

Every ServiceNow instance has an OOB page for codesearch: https://<INSTANCE_NAME>.service-now.com/nav_to.do?uri=/ui_page.do%3Fsys_id%3D8bc77fb2d7120200b6bddb0c825203ac It’s very useful, searches everywhere in your development codebase.

Get instance URL in server side scripting

Server URL is stored in following property. gs.getProperty('glide.servlet.uri') Note 1: This property does not exists in the sys_properties table, but hard coded in javascript execution scope. Note 2: The property may return an unpredictable value while running on the on-premise instances.

Auto-login to an instance with URL parameters

There is a possibility to login to the instance via the URL. You just pass you login name and password via URL paremeters like follows: https://{INSTANCE_NAME}.service-now.com/login.do?user_name={USER_NAME}&sys_action=sysverb_login&user_password={PASSWORD} Just replace marked placeholders with your real data and you are good to go. But note: of course, this is a very unsecure way of logging in.

UI Macro: Context menu for a form header

Not an easy to find functionality is hidden in this UI macros. It is being loaded on every form and renders context menu: context_form_header

Manipulate URL from client script

Useful snippets for working with URL from a lient script Redirect to a page with a form for creating a new record var query = [ "active=true", "short_description=Created " + moment().format("YYYY-MM-DD") ].join("^"); var url = new GlideURL("incident.do"); url.addParam("sys_id", "-1"); url.addParam("sysparm_query", query); window.location = url.getURL();

Working with g_list

Variable selectedSysIds will consist of sys_id`s of selected records. To be used from a UI Action (List). var selectedSysIds = g_list.getChecked();

Encoded query

Most of the times its much easier to work with encoded query instead of builing a query with GlideRecord API: var query = "category=Hardware^priority=1"; var gr = new GlideRecord("incident"); gr.addEncodedQuery(query); gr.query(); Encoded query is also useful for populating data to a GlideRecord object: var query = "category=Hardware^priority=1"; gr = new GlideRecord('incident'); gr.applyEncodedQuery(query); gr.insert();

Using GSLog

GSlog is the best way to output log infos from ServiceNow server scripts. Consider this snippet to get started. var logger = new global.GSLog('','My script'); logger.setLevel(global.GSLog.DEBUG); logger.includeTimestamp(); logger.logDebug('Hello World');

Setup autocomplete for a reference field

Another tiny guide