TUESDAY, FEBRUARY 07, 2012

Populating Default Values with a URL or Module

A

URL in Service-now 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 Service-now 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

Tags:  , ,

Comments

Posted On
Apr 30, 2010
Posted By
Brian Broadhurst

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

Posted On
Apr 30, 2010
Posted By
Mark Stanger

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.

Posted On
Dec 31, 2011
Posted By
Scott Hetzel

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

Posted On
Jan 03, 2012
Posted By
Scott Hetzel

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

Leave a Reply


Notify me of followup comments via e-mail. You can also subscribe without commenting.

Latest Comments

  • Mark Stanger: This linkage all happens for you if you use the task survey plugin. You can look on the wiki for more...
  • Vineeth: I want a way in which if a survey is filled in by the user the response are stored in the survey response...
  • Mark Stanger: This functionality doesn’t connect to an FTP server. See this line in the post above…...
  • Mark Stanger: The report page is back-end XML so there’s no way to directly manipulate the behavior of that...