How do I use the OR and AND operator in the sysparm_query parameter in a URL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2018 12:35 PM
Hi,
I'm trying to write query in the URL string sysparm_query that uses the OR operator. I'm trying to select all incidents that have a category of "A" or "B". In SQL, I would write the query like this,
select *
from Incidents
where category = 'A'
or category = 'B'
How do I write the same query in a URL query to send to the ServiceNow REST service? For example, I tried sysparm_query=category=AORcategory=B but it does not give me the correct information.
Thanks,
Hang

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 12:52 PM
The best method is to filter that information like in your list view. Then in the bread crumb, right-click the last entry and choose:
See also: https://docs.servicenow.com/bundle/helsinki-platform-user-interface/page/use/navigation/concept/c_Na... for guidelines
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 01:13 PM
You can use either OR operation or IN operation to filter by one from many categories. In case of filtering by software or hardware categories for example you can use
category=software^ORcategory=hardware
or alternatively
categoryINsoftware,hardware
The next example
category=software^incident_state!=7^NQcategory=hardware^incident_stateIN1,2
means
(Categoty='Software' AND Incident_State<>'Closed') OR (Category='Hardware' AND Incident_State IN ('New','In Progress'))
For more information about encoding queries see here, for example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 01:44 PM
Thanks Olegki,
What does ^NQ means? Is the ^NQ the same as OR?
Thanks,
Hang

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 01:59 PM
New Query, which is two queries held together by an OR statement
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!