I have known for quite some time that you can export records from any table from a URL (assuming you have rights to access that table). Several months ago, I discovered that you could not only get list information, but you could also filter it. Today, I found out that beyond filtering, you have the power to group the list results from the filter.
Let me explain how to use filters and groups with Service-now.com list URL’s.
According to the Service-now wiki on the “Exporting Data” page, you can export a number of records from a service-now table by appending a processor at the end of the URL. For example, if I want to export the records in the incident table as XML, I would format my URL like so:
http://myinstance.service-now.com/incident.do?XML
I could also export it into a CSV file in the following (and similar) way:
http://myinstance.service-now.com/incident.do?CSV
Now, what if I wanted to filter out the results a little bit. For example, what if I only wanted to export the “Active” incidents?
In order to use a filter in your export, you append the following parameter in the URL: “sysparm_query”. For example, if you wanted to export all active incidents into XML, you would use the following URL:
http://myinstance.service-now.com/incident.do?XML&sysparm_query=active=true
Let’s say you also want to only show those incidents where the category field is set to “hardware”. You can add this field to the query by using the “^” character between filter fields. Here is this example below:
http://myinstance.service-now.com/incident.do?XML&sysparm_query=active=true^category=hardware
Now let’s say we want to group those results by priority such that the priority 1 items will all be shown together (and so on for all other priorities). In order to do this, you use the keyword: EQ^GROUPBY just before the field that you wish to group results to. See the example below:
http://myinstance.service-now.com/incident.do?XML&sysparm_query=active=true^category=hardware^EQ^GROUPBYpriority
For an added bonus, you can make all of your exported reference fields show display values instead of ID numbers for their target tables by adding the following parameter to your URL: “displayvalue=true”.
If we wished to do this for our filtered group created in this article, we could simply append the parameter to the url like so:
http://myinstance.service-now.com/incident.do?XML&sysparm_query=active=true^category=hardware^EQ^GROUPBYpriority&displayvalue=true
This is really useful, thanks.
Can you add OR parameters to the URL in this way? e.g. if I want active = false OR incident_state = 6 on a url that points to the incident table?
Yeah, for example, the URL for all incidents that are:
could be represented as:
https://INSTANCENAME.service-now.com/incident_list.do?sysparm_query=incident_state!=7^priority=2^ORpriority=3
I’ve tried this, and it worked nicely, thanks.
I’d be interested to know how this is interpreted. The OR is at the end in your and my examples, but in a more complicated query, such as
(incident state = 6 OR incident state = 7) AND (priority = 2 OR priority = 3)
since we can’t use brackets, this looks tricky to use in a URL as it can be interpreted in so many ways, most of them wrong!
Is there a way to encode this into a url so that it interpreted correctly?
Many thanks!
Very good question. I went ahead and modified the ServiceNow wiki to show a neat little trick that I use to generate any of my Encoded Queries. It should handle your question about nesting.
You can build a filter on a list and then generate an encoded query. Filters can have nested AND/OR functions.
Check out my addition to the wiki at:
http://wiki.service-now.com/index.php?title=Embedded:Encoded_Query_Strings#Generating_Encoded_Query_Strings_through_a_Filter
Heading there now.
Many thanks John.
nic work….
Can you put some more articles specialy on workflows..
Gupta,
Workflows are sadly not my strong point. I don’t have very many opportunities to use them. I am more of an integrations specialist. If I do dabble in some workflows in the future, you can bet I’ll be posting my findings here.
Best Regards,
John
Not lookin for enable whenever you want it can bee a
surefire strategy too dig you right ito a hole.
In order to derive best outcomes from orgqnic SEO marketing,
it vital to target each page separately.