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 02:15 PM
You can find the meaning of ^NQ and many other operators on the page of documentation, which I referenced before in my answer. ^NQ means new query filter. The syntax of Query has no brackets `(...)`. ^NQ forces calculation of the first and the last parts as separate queries (filter condition) connecting results with OR. The usage of ^OR instead of ^NQ
category=software^incident_state!=7^ORcategory=hardware^incident_stateIN1,2
will generate
Categoty='Software' AND (Incident_State<>'Closed' OR Category='Hardware') AND Incident_State IN ('New','In Progress')
instead of
(Categoty='Software' AND Incident_State<>'Closed') OR (Category='Hardware' AND Incident_State IN ('New','In Progress'))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2024 01:39 AM
To use the OR operator in a ServiceNow URL query, you need to use the caret (^) symbol. Here's how you can write your query:
- sysparm_query=category=A^ORcategory=B
This will select all incidents that have a category of "A" or "B".
Here's the breakdown:
- sysparm_query: This is the parameter used to filter the data returned by the ServiceNow REST service.
- category=A: This is the first condition. It selects all incidents where the category is "A".
- ^OR: This is the OR operator. It allows you to select incidents that meet either the first condition or the second condition.
- category=B: This is the second condition. It selects all incidents where the category is "B".
So, the entire query sysparm_query=category=A^ORcategory=B will select all incidents where the category is either "A" or "B".
nowKB.com
If you want to know any information about Service Now . Visit to https://nowkb.com/home