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.
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.
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.
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
Variable selectedSysIds
will consist of sys_id`s of selected records. To be used from a UI Action (List).
var selectedSysIds = g_list.getChecked();
Useful snippets for working with URL from a lient script
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();
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();
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');
Admins getting security constraints even though ACL has Admin override checked