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();
Variable selectedSysIds will consist of sys_id`s of selected records. To be used from a UI Action (List).
var selectedSysIds = g_list.getChecked();
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');
Get all fields of a source record and clone into a new one
A simple code snippet for getting a GlideRecord
How to redirect to another portal from record producer