How to add a NOT equals condition to a Rest API URL

santrym
Mega Expert

I am trying to add a NOT equals conditional statement to this example URL. I want all incidents from a particular user where the state does NOT equal 6. Is there any way to do this? I can't seem to find any helpful service-now REST API condition help sheets/examples.

https://myCompany.service-now.com/api/now/table/incident?assigned_to=5fcf27f40f5b555557fb588755555e2...

Any thoughts/advise is appreciated! Thanks

1 ACCEPTED SOLUTION

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Michael,



Use an encoded query:


api/now/table/incident?sysparm_query=assigned_to%3D5137153cc611227c000bbd1bd8cd2007^state!=7



This is specified in the documentation here:


https://wiki.servicenow.com/index.php?title=Table_API#GET_.2Fapi.2Fnow.2Fv1.2Ftable.2F.28tableName.2...



You should use an encoded query in this case because URL parameters do not support the full semantics of a filter. URL params are limited to key:value pairs (assigned_to = some_value) or just keys (&XML for instance, to view the XML of a record in ServiceNow):


/incident.do?sys_id=i8d6353eac0a8016400d8a125ca14fc1f&XML



But there is no concept of a negation in URL parameters. That has to be done by parsing the *value* of a specified parameter, and the system being smart enough to turn that into a meaningful statement. So the URL:


api/now/table/incident?assigned_to=5137153cc611227c000bbd1bd8cd2007&state!=6


will be parsed as "assigned_to is some user" AND "'state!' is 6".



By using an encoded query, you get the full range of ServiceNow's filtering ability.



Thanks,


Cory


View solution in original post

4 REPLIES 4

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Michael,



Use an encoded query:


api/now/table/incident?sysparm_query=assigned_to%3D5137153cc611227c000bbd1bd8cd2007^state!=7



This is specified in the documentation here:


https://wiki.servicenow.com/index.php?title=Table_API#GET_.2Fapi.2Fnow.2Fv1.2Ftable.2F.28tableName.2...



You should use an encoded query in this case because URL parameters do not support the full semantics of a filter. URL params are limited to key:value pairs (assigned_to = some_value) or just keys (&XML for instance, to view the XML of a record in ServiceNow):


/incident.do?sys_id=i8d6353eac0a8016400d8a125ca14fc1f&XML



But there is no concept of a negation in URL parameters. That has to be done by parsing the *value* of a specified parameter, and the system being smart enough to turn that into a meaningful statement. So the URL:


api/now/table/incident?assigned_to=5137153cc611227c000bbd1bd8cd2007&state!=6


will be parsed as "assigned_to is some user" AND "'state!' is 6".



By using an encoded query, you get the full range of ServiceNow's filtering ability.



Thanks,


Cory


johnram
ServiceNow Employee
ServiceNow Employee

The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: Table API




Visit http://docs.servicenow.com for the latest product documentation


Luca14
Giga Contributor

Hi

 

I have a similiar question.

 

How can I add OR statements by using the following REST API URL:

 

https://company.service-now.com/api/now/stats/incident?sysparm_count=true&assignment_group=Grup-Name&state=2

 

I tried the following way:

 

https://company.service-now.com/api/now/stats/incident?sysparm_count=true&assignment_group=Grup-Name&state=2^OR_state=3

 

Thanks in adwance

atom88
Kilo Contributor

Have you tried the | (for the OR operator), that is typically used in logical operations:

 

^ = AND

! = NOT

| = OR