Ways to Pass Data Between Server, Client and Pages in ServiceNow

Hi there,

As I continue working on the HRSD implementation for a global company, I come across different problems. I enjoy the process of solving problems and now, with the help of AI, the process is even more interesting. I can ask it questions about anything, no matter how stupid :) I don't think that a human colleague would have the time and the patience to anwer all those questions :) That's probably the new way of learning nowadays.

I thought about compiling this list after looking for solutins and implementing a couple of them.  Such as:

‍

- Client script reading URL parameters, to populate fields on load

- UI Messages (getMessage), for translated text in client scripts

- Advanced reference qualifier, to filter which records a reference field offers

- Event parms, to send a notification to a recipient a Flow Action looked up — in my case a manager’s email, passed as parm1 to Fire Event

- Helper variables — hidden variables set by a client script, so a UI Policy can act on a value it cannot evaluate itself

- javascript: default values, set at the variable or dictionary level

‍

The list is compiled with the help of AI and it goes beyond the familiar approach of passing values in the URL and reading them with a client script.

Each entry was checked against ServiceNow documentation or Community posts.

The Example column is illustrative. Field, variable, page and event names are placeholders.

‍

One remark on the helper variables: hidden does not mean empty. The value still reaches the server on submit, so it can surface in the case description or the variables formatter.

I wrote about that gap, and how to work around it, here: https://victoriamunteanu.com/post/servicenow-hrsd-the-client-server-state-gap

‍

‍

Hopefully this will help someone, I'll use it as refence for future, nuttier, problems.

‍

# Name What it does How to set it up Example Status
1 sys_id=-1&sysparm_query Opens a new record with fields pre-filled.

Use sys_id=-1 in the form URL to open a new record, and put the field values in sysparm_query, separated by ^.

Example: nav_to.do?uri=incident.do?sys_id=-1&sysparm_query=priority=1^incident_state=3

The docs also show javascript:gs.getUserID() as a value, e.g. ^caller_id=javascript:gs.getUserID().

Docs example: incident.do?sys_id=-1&sysparm_query=priority=1^caller_id=javascript:gs.getUserID()

Verified
2 Client script reading URL parameters Copies URL values into catalog variables.

Write a catalog client script (onLoad) that parses document.URL and calls g_form.setValue, e.g. document.URL.parseQuery().

Set the script's UI Type to All so it also runs on Employee Center.

One user got a "document is null" error in a scoped app and fixed it by creating the script in global scope.

var p = document.URL.parseQuery();

if (p.company) g_form.setValue('u_example_var', p.company);

Verified
3 sysparm_variable_values Native catalog prefill from the URL (Zurich and later).

Add sysparm_variable_values to the catalog item URL as JSON of variable names and values.

Reference variables need a sys_id. Catalog Client Scripts and UI Policies still run as if the user typed the values.

Controlled by the property glide.sc.enable_url_prefill (on by default). Portal widgets also have a "Disable URL prefill" option.

Not supported: attachment, custom, custom with label, masked, UI page, label/container, and multi-row variable sets (MRVS).

/sp?id=sc_cat_item&sys_id=<item_sys_id>&sysparm_variable_values={"u_region":"EMEA","u_cost_centre":"4711"}

Use your own portal URL prefix and variable names.

Verified
4 variableValues property Prefill for Next Experience and Virtual Agent.

Next Experience: All > Now Experience Framework > Experiences, select the UX app, Open in UI Builder, then add key-value pairs on the catalog item component property.

Virtual Agent: open the "Request Catalog Item Inline" topic and enter a stringified JSON object in variableValues.

Virtual Agent variableValues:

{"u_region":"EMEA","urgency":"2"}

Verified
5 g_scratchpad Sends server data to client scripts at form load.

Create a Business Rule with When = Display and set g_scratchpad.yourName = value;.

In any client script (onLoad, onChange, onSubmit) read g_scratchpad.yourName.

Defined only in Display Business Rules; data is loaded once at form load. Use GlideAjax for dynamic lookups.

Display Business Rule:

g_scratchpad.isAssignedToMe = (current.assigned_to == gs.getUserID());

Client script:

if (g_scratchpad.isAssignedToMe) { /* ... */ }

Not confirmed for Workspace.

Verified
6 putClientData / getClientData Passes session data from server to client.

Server script: gs.getSession().putClientData('key', value);

Client script: g_user.getClientData('key');

Docs suggest using it at form load to decide things like which fields to show.

Server (e.g. Display Business Rule):

gs.getSession().putClientData('is_approver', 'true');

Client script:

var f = g_user.getClientData('is_approver');

Verified
7 g_user.setClientData() Stores a value on the client for later reads.

Call g_user.setClientData(key, value) and read it back with g_user.getClientData(key).

The docs show an onSubmit script that caches a looked-up value this way.

onChange:

g_user.setClientData('lastCompany', newValue);

onSubmit:

var c = g_user.getClientData('lastCompany');

Verified
8 UI Page parameters (Jelly) Takes URL parameters in a UI Page.

Open the page as <ui_page_name>.do?sysparm_x=value and read it in Jelly with ${RP.getParameterValue('sysparm_x')}.

Another suggestion is $[parameter_name]. Load the page by its name, not through ui_page.do?sys_id=....

Community answers are mixed: in one thread RP.getParameterValue returned blank for some parameters.

URL: my_page.do?sysparm_record=<sys_id>

Jelly:

<g:evaluate var="jvar_rec" expression="RP.getParameterValue('sysparm_record')" />

${jvar_rec}

Verified, with caveats
9 UI Messages (getMessage) Server-managed strings, cached on the client if preloaded.

Create a record under System UI > Messages with a key, then call getMessage('key') in a client script.

Also list the key in the client script's Messages field. This preloads it and avoids a server round trip. Without it, getMessage() calls the server.

getMessages([...]) fetches several keys at once.

Create the key my.app.date_warning in System UI > Messages, and list it in the client script's Messages field.

g_form.showFieldMsg('start_date', getMessage('my.app.date_warning'), 'error');

Verified
10 g_form.getReference() Reads a referenced record's fields without a Script Include.

In a client script (often onChange): g_form.getReference('assigned_to', function(ref){ ... ref.getValue('field') ... });

Always pass a callback so it runs asynchronously.

It fetches the whole record, which can be slow. GlideAjax is better when only one or two fields are needed.

g_form.getReference('assigned_to', function(ref) {

g_form.setValue('u_assignee_email', ref.getValue('email'));

});

Verified
11 Advanced reference qualifier Filters a reference field's choices using other values.

Set the qualifier to Advanced, e.g. javascript: new YourScriptInclude().fn(current.variables.field_1) (no quotes around the variable).

If the dependent value is not picked up on a catalog variable, add the variable attribute ref_qual_elements=<variable> (comma-separate several).

Limit: variables inside and outside a multi-row variable set cannot be used in each other's dependent qualifiers.

Variable reference qualifier:

javascript: new MyQualifierUtils().groupsFor(current.variables.u_region)

The Script Include method returns an encoded query, e.g. 'active=true^nameLIKE' + region.

Add ref_qual_elements=u_region to the dependent variable if needed.

Verified
12 Session putProperty / getProperty Server-side values kept for the user's session.

var s = gs.getSession(); s.putProperty('name', 'val'); s.getProperty('name');

Separate from the client-readable putClientData.

gs.getSession().putProperty('last_record', current.sys_id.toString());

Later in the same session: gs.getSession().getProperty('last_record');

Verified
13 User preferences Persists a per-user value across sessions.

gs.getUser().savePreference('myPref', 'red'); then gs.getUser().getPreference('myPref');

Values are stored in the sys_user_preference table.

gs.getUser().savePreference('myapp.last_tab', 'tasks');

gs.getUser().getPreference('myapp.last_tab');

Verified
14 sysparm_query on a list URL Opens a pre-filtered list.

https://<instance>/nav_to.do?uri=incident_list.do?sysparm_query=active=true^escalation=2

Without the navigation frame: https://<instance>/incident_list.do.

nav_to.do?uri=incident_list.do?sysparm_query=active=true^priority=1

Verified
15 sysparm_view Forces a specific form view.

Add &sysparm_view=<view name> to the form URL. An empty value gives the Default view; ess loads the Self Service view if one exists.

View names (not labels) are in the Views [sys_ui_view] table.

Switching views also saves a user preference, so the form reopens in that view.

nav_to.do?uri=incident.do?sys_id=<record_sys_id>&sysparm_view=ess

Verified
16 Event parms Passes data from a script to a notification.

Register the event, then call gs.eventQueue('event.name', current, parm1, parm2);

On the notification, set Send when = "Event is fired". Tick "Event parm 1 contains recipient" if parm1 holds recipients.

Read values in the message as ${event.parm1} and in email scripts as event.parm1.

gs.eventQueue('x_myapp.record.notify', current, recipientEmail, '');

With "Event parm 1 contains recipient" ticked on the notification.

Verified
17 Helper variables Hidden values that drive UI Policies.

Add a hidden checkbox or text variable, set it from a client script with g_form.setValue(...), and reference it in the UI Policy condition.

Commonly used when the real condition depends on a GlideAjax result that a UI Policy cannot evaluate on its own.

onLoad client script, after a GlideAjax callback:

g_form.setValue('u_is_eligible', data.isEligible ? true : false);

UI Policy condition: "Is eligible" is true.

Common practice
18 javascript: default value Computes a default value when the form loads.

Right-click the field label, choose Configure Dictionary, and enter the script in Default value, e.g. javascript:gs.getUserID().

For catalog variables, put the same kind of script in the variable's default value.

Dictionary default on a reference-to-user field:

javascript:gs.getUserID()

Verified
19 GlideDialogWindow.setPreference() Passes values into a UI Page opened as a dialog.

In a client-side UI Action: var d = new GlideDialogWindow('page_name'); d.setPreference('sysparm_sysid', value); d.render();

GlideModal is reported to work the same way. One user got null with both RP.getParameterValue and getWindowProperties, so test it.

UI Action (client):

var d = new GlideDialogWindow('my_dialog_page');

d.setPreference('sysparm_record', g_form.getUniqueValue());

d.render();

UI Page:

<g:evaluate var="jvar_rec" expression="RP.getWindowProperties().get('sysparm_record')" />

Verified, with caveats
20 $sp.getParameter() / $location.search() Reads URL parameters in a Service Portal widget.

Server script: data.value = $sp.getParameter('sharedValue');

Client controller: inject $location and call $location.search().

Server script: data.recordId = $sp.getParameter('record_id');

Client controller: var q = $location.search(); c.recordId = q.record_id;

URL: ?id=my_page&record_id=<sys_id>

Verified
21 $rootScope.$broadcast Passes data between widgets on a page.

Sender: $rootScope.$broadcast('myEvent', value);

Receiver: $scope.$on('myEvent', function(event, v){ ... });

Wrap the broadcast in a short $timeout so other widgets are loaded and listening. $emit only notifies $rootScope.$on listeners.

Sender: $rootScope.$broadcast('record.selected', c.recordId);

Receiver: $scope.$on('record.selected', function(e, id) { c.recordId = id; });

Verified
  • Verified — confirmed in a ServiceNow doc or Community source.
  • Verified, with caveats — confirmed, but community reports mixed results. Test on your instance.
  • Common practice — a widely used pattern rather than a documented feature.

ServiceNow product documentation

  1. GlideUser – Client API (setClientData, getClientData) www.servicenow.com · supports #6, 7
  2. GlideUser – Scoped API (savePreference, getPreference) www.servicenow.com · supports #13
  3. Examples of navigating by URL www.servicenow.com · supports #1, 14, 15
  4. Specify a default field value www.servicenow.com · supports #18
  5. Message API (sn_i18n) www.servicenow.com · supports #9

ServiceNow Community – articles and blogs

  1. 3 ways to populate values in ServiceNow via the URL www.servicenow.com · supports #1, 2, 8
  2. Adventures in Service Portaling: populate catalog variable values www.servicenow.com · supports #2
  3. URL navigation tips www.servicenow.com · supports #14, 15
  4. How to communicate between widgets in Service Portal www.servicenow.com · supports #21
  5. Client script messages and System UI > Messages www.servicenow.com · supports #9

ServiceNow Community – forum threads

  1. How to auto-populate ServiceNow form fields using a URL query www.servicenow.com · supports #1, 2
  2. Is there any way to populate variables of a catalog item using a URL? www.servicenow.com · supports #2
  3. What is the use of getReference on the client side? www.servicenow.com · supports #10
  4. Client scripts (getReference callback usage) www.servicenow.com · supports #10
  5. What is Event parm 1 and Event parm 2 in an email notification? www.servicenow.com · supports #16
  6. How to pass a parameter in an event www.servicenow.com · supports #16
  7. GlideSession: when to use get/setProperty versus get/putClientData www.servicenow.com · supports #7, 12
  8. Calling a record producer variable in an advanced reference qualifier www.servicenow.com · supports #11
  9. How to set a variable value as a reference qualifier in a lookup www.servicenow.com · supports #11
  10. Reference qualifier on a catalog multi-row variable set www.servicenow.com · supports #11
  11. How to get values from fields in a portal form widget and pass them on www.servicenow.com · supports #20, 21
  12. How to pass data from one Service Portal page to another www.servicenow.com · supports #20
  13. Pass params from a UI Action to a UI Page www.servicenow.com · supports #19
  14. How can I get the current record’s sys_id in a UI Page? www.servicenow.com · supports #19
  15. Trouble using UI Action variables in a UI Page www.servicenow.com · supports #19
  16. Jelly script: get a parameter from the URL www.servicenow.com · supports #8
  17. Parsing a value returned from RP.getParameterValue www.servicenow.com · supports #8
  18. What is the difference between getMessage and getMessages? www.servicenow.com · supports #9
  19. Usage and benefit of the Messages field on client scripts www.servicenow.com · supports #9