SN Widget Kit logoSN Widget Kit
Docs

Server & Debug

server.js running locally

The preview executes your Server Script in a Node sandbox, with faithful stubs of the ServiceNow API.

Server-side APIs

  • gs getUser() (with getDisplayName, getEmail, getLocation, hasRole, …), nowDateTime, info/warn/error, addInfoMessage/addErrorMessage, date helpers, getProperty, and 80+ methods
  • GlideRecord — when logged in, runs real queries via the Table API: addQuery, addEncodedQuery, orderBy, get(sysId), getValue, getDisplayValue, and dot-walking (gr.caller_id.name.toString())
  • GlideAggregate addAggregate('COUNT'|'SUM'|'AVG'|'MIN'|'MAX'), groupBy, orderBy(Desc) (live or from fixtures)
  • Script Includes new global.MyScriptInclude().method() is loaded on demand from the instance, evaluated and executed
  • RESTMessageV2 / sn_ws.RESTMessageV2 — real outbound HTTP from server.js: setEndpoint, setHttpMethod, setRequestBody, execute() RESTResponseV2. A relative endpoint resolves against the active instance with your session auto-injected; third-party hosts never receive your instance credentials
  • GlideDateTime — UTC-correct, ~30 methods: addSeconds/addDays/addWeeks/addMonthsUTC, subtract, before/after/equals/compareTo, getDayOfWeekUTC, …
  • gs.getProperty(name) reads the real sys_properties value (cached per run), with default fallback
  • gs.getMessage(key, args) and ${key} tokens resolve against your instance's sys_ui_message (with {0}/{1} substitution)

gs.addInfoMessage(...) / spUtil.addInfoMessage(...) show up as banners at the top of the preview, just like the portal. There's a logs panel (gs.info/warn/error) in the preview's top bar.

Offline behavior
Without login (or with offlineMode on), gs and GlideRecord use stub/fixture data; the widget still renders, but without real data. See Offline development.

Client-side APIs in the preview

The preview also provides faithful Service Portal client APIs so client.js behaves like the portal:

  • spModal alert / confirm / prompt / open render a real modal and return a $q promise. Embedded HTML renders, ${token} labels are translated, and cancel rejects the promise — so .then(onOk, onCancel) works exactly as on the instance
  • spUtil get(widgetId, data) resolves a widget model ($q), recordWatch returns an unsubscribe handle, plus addInfoMessage/addErrorMessage, format, etc.
  • g_form / g_user — available as ambient globals: in-memory g_form seeded from your boot data, and g_user from your live (or preview) user
Embedded widgets
Embedded widgets (<sp-widget> / <widget> / spUtil.get) currently render as a labeled placeholder — the nested widget tree is not yet executed offline. Use the real portal for those.

High-fidelity artifacts (opt-in)

Complex widgets that rely on Angular sp_ng_templates, sp_angular_providers or shared dependency CSS can enable snWidgetKit.highFidelityArtifacts. When on (and logged in), the preview fetches those related records and injects them. Off by default, since it runs widget-provided Angular code and adds instance calls.