Populating Default Values with a URL or Module

A URL in ServiceNow is more than it seems at first glance. The various components of a URL actually contain quite a bit of information about what the system will do when that URL (or link) is used.  One way that you can leverage the ServiceNow URL structure is by using the ‘sysparm_query’ argument to return a list of certain records.  You can also use ‘sysparm_query’ as a way of setting default values on a new record if necessary. This article shows you how.

This URL opens a new incident record with default values for ‘Active’, ‘Priority’, and ‘Short Description’.

https://demo.service-now.com/incident.do?sysparm_stack=incident.do&sys_id=-1&sysparm_query=active=true^priority=1^short_description=URL%20Default%20Value^EQ

Another place where you can apply the same concept is in module links in the left navigation pane. Since modules use the defined module parameters to create a URL, you can leverage the module filter and arguments to create ‘sysparm_query’ arguments in your module link. Simply create a module with a ‘Link Type’ of ‘New Record’ on whatever table you want and populate the ‘Filter’ field with the field/value pairs you want. This image shows how you could create a module to open a new incident record with default values for ‘Active’, ‘Priority’, and ‘Short Description’.


Module Default Value

Date Posted:

March 18, 2010

Share This:

10 Comments

  1. Brian Broadhurst April 30, 2010 at 7:44 am

    Hi Mark,

    I wonder if you could give a little more detail about the syntax of the sysparm_query clause in a URL. I’ve recently been trying to use a reference qualifier to do a query that consists of a number of ANDs and ORs for which I would like to be able to use parentheses – but the URL syntax doesn’t seem to allow that. As an example, suppose I want to restrict the list of CIs that are presented when you click the magnifying glass on an Incident form to those where either the Company is as entered on the Incident or the Location is as entered on the Incident, but the Install Status must also be In Service. The kind of sysparm_query I want to generate is:

    install_status=1^(company=XYZ Inc^ORlocation=London)

    The query doesn’t work with the parentheses there, but without them, how is the query evaluated – is there a precedence such that OR gets evaluated before AND or vice versa? Or are the operators evaluated in sequence from left to right, in which case my query above (minus the parentheses) would return all the CIs that belong to XYZ Inc that are also In Service plus all the CIs that are in London regardless of their Install Status.

    Brian

    • Mark Stanger April 30, 2010 at 9:16 am

      Hey Brian,

      My experience has been that the ‘OR’ gets evaluated before the ‘AND’. That being the case, your query should return exactly what you think it should if you remove the parentheses.

  2. Scott Hetzel December 31, 2011 at 10:53 am

    Good info..

    I used this trick to set a Change “type” with an interceptor instead of defining a view with an interceptor. The target URL I used:

    change_request.do?sysparm_stack=change.do&sys_id=-1&sysparm_query=type=Expedited

    • Scott Hetzel January 3, 2012 at 3:52 pm

      Correction from my post regarding interceptor above: better to use; ‘change_request.do?sysparm_query=type=Normal^state=1’ or similar. My sysparm_stack is wrong and not needed for my use case.

      Regards,
      Scott

  3. Will June 12, 2012 at 10:29 am

    I’m trying to use this in order to populate a specific CI into the incident or request, but haven’t been able to get it to work. Do I need to use the sysID or the text? here is the link in the ‘Create New’ incident module: incident.do?sys_id=-1&sysparm_query=active=true&sysparm_stack=incident_list.do?sysparm_query=active=true

    I tried adding an &sysparm_query=cmdb_ci=sysid

    Where sysid is I put the sys id, but it didn’t work. Any suggestions?

    • Mark Stanger June 12, 2012 at 10:34 am

      You only need one ‘sysparm_query’ parameter in your URL. You also need to use the ‘sys_id’ if you’re using URL arguments. Something like this should work…
      incident.do?sys_id=-1&sysparm_query=active=true&sysparm_stack=incident_list.do?sysparm_query=active=true^cmdb_ci=YOURCISYSIDHERE

      Having said that, if you’re doing this from a ‘Create new record’ module, then you shouldn’t need to add ‘sysparm_query’ parameters or arguments at all. You can just use the filter on the module definition to supply the values you want to set in the new record.

      • will June 13, 2012 at 10:45 am

        Thanks Mark, got it working late yesterday.

  4. Jim August 29, 2012 at 12:45 pm

    Mark,
    I am trying to use this as well, but I want to use with an order guide. When a person is hired, I want to send an email to the hiring manager with a link to the new user provisioning screen with the user name populated. My link brings me to the right screen, but the variable, “requested_for” is not populated.
    ……service-now.com/com.glideapp.servicecatalog_cat_item_guide_view.do?sysparm_initial=true&sysparm_guide=37c517ae0a0a0a6a00c2ee57a47ebddf&sysparm_query=requested_for=odonohus
    Should I be using a different syntax for the variable>

  5. Aleksandr Stepurin November 19, 2013 at 4:16 pm

    Hi to all,

    Thanks for this information really useful!

    I have a question: is there any way to save incident using URL? I mean to create and save incident in Opened state using URL in one go.

    Thanks in advance.

Comments are closed.

Categories

Tags

Loading

Fresh Content
Direct to Your Inbox

Just add your email and hit subscribe to stay informed.