Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How do we add Not equal to condition to REST API url

Rajanmehta
Mega Guru

hi

We are on Helsinki. Can someone please help and show me how to add Not Equal to condition to REST API url?

Please see the url below. And I want to filter out sys_class_name = Hyper-V Server from the result set. (i.e. sys_class_name =! 'Hyper-V Server')

The way I have added it, doesn't work.

Please advise.

Thanks,

https://XXXXXX.service-now.com/api/now/table/cmdb_ci_server?sysparm_query=&sysparm_fields=name%2Cos%...

Rajan Mehta

1 ACCEPTED SOLUTION

I'm not on my computer right now, so I don't know the system name of the host name field, but the easiest way to build your query is go to cmdb_ci_list.do in your instance. Then use the filter to add all of the conditions you want and verify your results are correct.



then right click the filter text and click copy query. This will copy the encoded query for you, and then you can put that right after sysparm_query= in your URL.


View solution in original post

8 REPLIES 8

Shishir Srivast
Mega Sage

Hi Rajan,



Provided link is not getting open, but i noticed that you are using equal not (=!) instead, please try Not Equal (!=). Thank you!


Hello Shishir,



I tried doing it that way, but still it doesn't filter.



"https://XXXXX.service-now.com/api/now/table/cmdb_ci_server?sysparm_query=sys_class_name!=Hyper-V%20S..."



Any idea.



Thanks,



Rajan Mehta


Jon Barnes
Kilo Sage

sysparm_query=sys_class_name!=cmdb_ci_hyper_v_server


Hello Jonathan,



I tried doing it that way, but still it doesn't filter.



"https://XXXXX.service-now.com/api/now/table/cmdb_ci_server?sysparm_query=sys_class_name!=Hyper-V%20S..."



Any idea.



Thanks,



Rajan Mehta