ServiceNow REST API support for parentheses in the sysparm_query parameter.

PuneethK
Kilo Contributor

Can we apply complex conditions (combinations of AND and OR with parentheses) while fetching data from ServiceNow resources?

We do have complex conditions to apply while fetching data.
Example: A AND B AND (C OR (D AND E)) AND (E OR F)

 

Sample example with query: (field1=value1 AND field2=value2) OR field3=value3

In ServiceNow's sysparm_query parameter, this can be formatted as below,

field1=(value1^field2=value2)^ORfield3=value3.

 

I receive a 403 error_code with the message:

 

{"error":{"message":"Insufficient rights to query records","detail":"Field(s) present in the query do not have permission to be read"},"status":"failure"}

 

 

It appears that parentheses are not interpreted correctly and are being treated as part of the field name.

Is there an alternative approach to achieve this?

 

1 REPLY 1

Praveen Mariapp
Tera Contributor

@PuneethK

You can try the query in this format: field1=value1^field2=value2^NQfield3=value3

This means, (field1=value1 AND field2=value2) OR field3=value3

 

e.g., caller_id.email=abraham.lincoln@example.com^active=true^NQcaller_id.vip=true

 

If this helps, please mark my answer helpful

If this provides solution, please mark this as correct answer

 

Regards,

Praveen