John Armstrong
ServiceNow Employee

As you may have noticed when navigating the smartphone mobile interface, the URL format is significantly different from what's used in the Desktop and Tablet UI.   This is important for a few reasons.   In additional to being able to identify where you're looking on the instance using the URL, this information can also be used to create links and modules specifically for use in the Mobile UI, as will be shown in the examples below.   I hope to better explain the URL structure, including information on how to apply filter options and auto-populate field data using the URL. Filter options and field data in the URL can be helpful both when viewing existing URLs to understand their content or in creating your own URLs to use in scripts.

 

 

This is the basic schema for a mobile URL:

https://<base URL>/$m.do#/<list/form>/<table>/q:<query>^<query>^EQ

 

Elements of a mobile URL include:

$m.do#This is where the mobile interface is specified.   Browsing to $m.do in any supported browser will display the Mobile UI.
<list/form>Using either "list" or "form" here will specify whether a list of form will be displayed by the URL.
<table>This is the table being accessed, such as "incident" or "change_request."
q:<query>^This is how queries are created.   These begin with q: and are separated by the carat (^) symbol. Examples below:
  • /$m.do#/list/incident: displays a list of all incidents
  • /$m.do#/list/incident/q:active=true: displays a list of all incidents where the "active" field is true
  • /$m.do#/!list/incident/q:active=true^priority=1:   displays a list of all incidents where the "active" field is true and the priority field is 1.
  • /$m.do#/form/incident/d71da88ac0a801670061eabfe4b28f77:   Displays the form for the incident record where the sys ID matches the sys ID "d71da88ac0a801670061eabfe4b28f77".   As with desktop URLs, form URLs in mobile use the record's sys ID.
  • /$m.do#/form/incident/-1:   As with the Desktop UI, a -1 can be used in place of a sys ID to create a new record.
^EQThe EQ denotes the end of the Query.

 

 

Generating a Record with a URL Link

Forms in mobile can be displayed with pre-populated fields, as they can in the desktop UI.   This can be useful, for example, when creating modules for your mobile UI.   For, example, take the "Create New" mobile module used to create new incidents in the mobile UI.  

 

You can find this on your instance by navigating to System Mobile UI → Navigator Apps, then selecting the "Incident" Application Menu.   In the Modules related list you'll see "Create New"

 

If you look at the Path field for this item, you'll see the URL used to create a new incident in the Mobile UI.

 

form/incident/-1

 

 

Let's say, for example, we wanted to create a module that created new incidents with pre-populated priority, short description, and assignment group.   This is an example URL we could use to accomplish that:

 

/$m.do#/form/incident/-1/priority=2^short_description=MY TEST^assignment_group=d625dccec0a8016700a222a0f7900d06

 

 

Let me break this down for you a bit:

/$m.do#/form/incident/-1/As with the desktop URL navigation, using a sys_id of -1 directs the instance to a new record form.
priority=2This sets the priority to "2 - High."   When setting values for choices, the value (2) is used rather than the label.
^As with list filters, each field is separated by a caret(^) symbol.
short_description=MY TESTThis sets the short description to "MY TEST."   Spaces are allowed, but characters that have meaning within a URL, for example a " \ " character, will not work and will break the URL.
assignment_group=d625dccec0a8016700a222a0f7900d06This last field is a reference field.   In this case, we're setting the Assignment Group to "Service Desk."   For a reference field like this one, we use the sys_id of the records being referenced, which, in this case is the is a sys_user_group record.

 

 

An Example of Use within ServiceNow

For an example of when something like this can be helpful, let's take a look at "Create Incident" record producer.   On this record producer is a script that first detects whether or not the scripts is being run in the Mobile UI, and then provides an appropriate link based on that information.

 

var isMobile = GlideMobileExtensions.getDeviceType() == 'm';

var link = isMobile ? '#/list/incident/q:active=true%5Ecaller_id=javascript:gs.user_id()%5EEQ' : 'home.do';

 

In the above script, when the Mobile UI is detected, a link using the URL formatting for mobile is selected. This will link to a list of active incidents where the Caller ID field matches the current user:

generate record.jpeg

 

As we've seen above, knowing the URL format for mobile will allow you to create links and modules for use in the Mobile UI.   With this information, you'll be able to create content on your instance specifically for mobile use, and provide a better experience for your mobile users.

 

A quick note about javascript used within mobile links:   While the example above works as expected, the Mobile UI does not support dynamic urls which direct to a form (specific record).

8 Comments