0

I need to query tables in ServiceNow via its REST API while using multiple conditions grouped as following:

( (Condition1 AND Condition2) OR (Condition3 and Condition4) ) AND Condition5 AND Condition6

Does anyone know if this is possible, and if so, how? I've looked into the documentation but I'm not able to understand if it explains how to solve my problem.

Edit 1: I forgot to mention that I did try using parenthesis in my REST calls but it has not worked.

Thanks,

Vishal
  • 2,103
  • 2
  • 16
  • 18

1 Answers1

1

The only way I've figured out how to do it is using the ^NQ (New Query) operator.

In SQL the query would look like this:

WHERE [state] IN (16,17) AND ([assigned_to] = 'value1' OR [assignment_group] IN ('x','y','z'))

So my query looks like this:

sysparm_query=stateIN16,17^assigned_to=value1^NQstateIN16,17^assignment_groupINx,y,z

So you're actually duplicating the common filter (state) and using different filters on each side of the ^NQ.

I guess you could say it would be the equivalent of a UNION in SQL.

SELECT * FROM [wm_task] WHERE [state] IN (16,17) AND [assigned_to] = 'value1'
UNION
SELECT * FROM [wm_task] WHERE [state] IN (16,17) AND [assignment_group] IN ('x','y','z')
tolsen64
  • 881
  • 1
  • 9
  • 22