_
_
Back to Blog
ServiceNow
Automation

Using Hidden Filter Conditions for ServiceNow Tags

Hidden ServiceNow Tag Filters for Smarter Queries
3
min read
|
by
Caleb Cordes
September 24, 2024

Sometimes, you need a way to organize data within ServiceNow without adding a new field to a table. It’s not the optimal solution for exporting data to an external database (the third-party DB may not support it). ServiceNow Tags are a great tactical solution for a quick win. If you work with tags from a List view, you'll notice a limitation of the UI. At face value, there is no operator for a Tags condition, and after clicking "Run," the resulting query will contain an inclusive "has" condition, which is represented as "%253D" in the URL. Not having a way to query for CIs that DO NOT have the assigned tag is annoying. However, there is an undocumented workaround. 

Ok, here's the pro tip that will allow you to work around this UI limitation. Merely replace the "%253D" value in the URL between the tag sys_id with "EXCLUDING" and then execute the URL again. The query will work, however, there are some limitations you will have to work with. 

  1. The filter builder will ignore the tag condition. So, just save the step of adding your tag condition until the end of your query.
  1. The "EXCLUDING" condition does not jive well with other conditions that are more advanced like the "is one of" or "is not one of." So, break up those conditions with "or" operator

The good news is that you can see the condition in the filter breadcrumb. So copying the encoded query from the context (right-click) menu works as expected

If you are curious, here's the story behind this pro tip. . .While the list view has the tag condition limitation, Report Builder (and Query Builder) does not. Go ahead and try it. Create a report with the tag condition, and you will see three operators! 

Save your report and then look at the filter parameter of the report's xml (sys_report). Search for “filter,” and you can see the encoded query with the tag condition.

  1. "has" : "="
  2. "does not have" : "DOESNOTHAVE" 
  3. "excluding": EXC "EXCLUDING"

Interested to learn more? Reach out to us at chat@rapdev.io

Written by
Caleb Cordes
Boston
A ServiceNow Architect living to make the world a better place through automation and meaningful design. Geeks out to any conversation about ITOM, CSDM and operationalizing ServiceNow as a Service Offering. Lives to be a super dad to his kids and inspired by his wife. When time allows, he is a woodworker, cyclist, and outdoorsman.
you might also like
back to blog