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

Rajan, you need to use the same as I typed exactly for it to work - you typed the hyper v server class name like the display value, but you need to use the one I suggested. Use cmdb_ci_hyper_v_server.   Try that and let me know.


Thanks Jonathan,



Awesome. That did work. Now I have one more condition to add to URL. Can you please guide me how or where do I add that?



Need to add condition host name contains "netapp" need to be exclude from the result.



Can I add at the end or it has to be with sysparm_query?



please advise.



Thanks,



"https://XXXXX.service-now.com/api/now/table/cmdb_ci_server?sysparm_query=sys_class_name!=cmdb_ci_hyp..."



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.


Perfect Jonathan.


That   did help.



Thanks,



Rajan Mehta