how do we implement AND and OR operations in rest table api

akshay317
Kilo Contributor

HI all,

I'm new to servicenow development. I need to access Incidents table in my developer instance via REST table apis. E.g I need those records having State=Closed or State=Awaiting Problem for a specific user (name: XYZ). But I'm not able to implement OR condition in the table api query. I'm hitting the table from an external service made in javascript. Here is my query form

("get", "https://devxxx.service-now.com/api/now/table/incident?sysparm_limit=10&sysparm_fields=location,numbe...");

Here I need to implement a OR query so as to fetch records for state=Awaiting Problem.

A quick response wolud be highly appreciable. Thanks in advance.

POSTED BY AKSHAY        

1 ACCEPTED SOLUTION

santoshsahoonis
Kilo Guru

Hello,



You have to send a sysparm_query along with the link:


example:



https://xxxxx.service-now.com/api/now/table/incident?sysparm_limit=10&sysparm_query=active=true^stat...



Your link(should work now): https://devxxx.service-now.com/api/now/table/incident?sysparm_limit=10&sysparm_fields=location,numbe...




for an AND operator use ^


for an OR operator use ^OR



You can get this encoded query from any List view :



find_real_file.png




View solution in original post

5 REPLIES 5

Chuck Tomasi
Tera Patron

My recommendation is build the query you want in the list filter first. For example,



find_real_file.png



Next, right click on the right-most breadcrumb to copy the query



find_real_file.png



Use the copied value as your sysparm_query



https://somesite.service-now.com/...&sysparm_query=active=true^priority=1^caller_id=681ccaf9c0a80164...


santoshsahoonis
Kilo Guru

Hello,



You have to send a sysparm_query along with the link:


example:



https://xxxxx.service-now.com/api/now/table/incident?sysparm_limit=10&sysparm_query=active=true^stat...



Your link(should work now): https://devxxx.service-now.com/api/now/table/incident?sysparm_limit=10&sysparm_fields=location,numbe...




for an AND operator use ^


for an OR operator use ^OR



You can get this encoded query from any List view :



find_real_file.png




Thanks Santosh and Chuck. It was a big help. I understood what I was missing.