How do I use the OR and AND operator in the sysparm_query parameter in a URL?

Hang Lam
Kilo Contributor

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

6 REPLIES 6

Allen Andreas
Administrator
Administrator

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:

find_real_file.png

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!

Oleg
Mega Sage

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

Hang Lam
Kilo Contributor

Thanks Olegki,

What does ^NQ means? Is the ^NQ the same as OR?

Thanks,

Hang

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!