Stuck in rest api date formula

s_gatade
Kilo Contributor

All,

To start with, I'm not sure if this is right forum to post my question!

I'm experimenting with Service NOW REST API and am stuck in a situation where I need to GET incidents created ON and/or AFTER a certain date. I'm not sure how to form the REST URL since normal ways of LESS THAN or GREATER THAN with proper date format are not working.

The following URL gives me the correct incident registered on the particular date i.e. opened_at=2013-04-18+06:37:37

https://xxxxxxxx.service-now.com/api/now/v1/table/incident?priority=3&sysparm_limit=10&sysparm_field...

But I need to get ALL the incidents OPENED AFTER this date... I've tries &gt, %3E%3D, >= and all combinations but am getting "No record found" message.

I've searched High & Low on ServiceNOW Wiki & other forums but no lead till now...

Please do let me know how this can be done...

Thanks in advance...

S. Gatade

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

When I use the REST API Explorer, it shows me this:



var request = new sn_ws.RESTMessageV2(); request.setEndpoint('https://dev14066.service-now.com/api/now/table/incident?sysparm_query=sys_created_on%3E%3Djavascript%3Ags.dateGenerate('2015-12-09'%2C'14%3A05%3A30')&sysparm_limit=10'); request.setHttpMethod('GET'); 


Capture.PNG



Capture.PNG


View solution in original post

5 REPLIES 5

Mike Allen
Mega Sage

When I use the REST API Explorer, it shows me this:



var request = new sn_ws.RESTMessageV2(); request.setEndpoint('https://dev14066.service-now.com/api/now/table/incident?sysparm_query=sys_created_on%3E%3Djavascript%3Ags.dateGenerate('2015-12-09'%2C'14%3A05%3A30')&sysparm_limit=10'); request.setHttpMethod('GET'); 


Capture.PNG



Capture.PNG


Thanks a lot Mike! I even tried javascript args sometime back but was not getting the correct one. I did play around with your URL and its working, I'll do some more tests later...



Thanks again for the prompt and correct response!!!


tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Shailendra,


You can create a query in a list view as required, copy it   and use it as per wiki below:



Table API - ServiceNow Wiki


http://wiki.servicenow.com/index.php?title=Table_API#Methods4.1 GET /api/now/v1/table/(tableName)


This method retrieves multiple records for the specified table with proper pagination information.



Supported Parameters


sysparm_queryAn encoded query.

For example: (sysparm_query=active=true)(sysparm_query=caller_id=javascript:gs.getUserID()^active=true)


Best Regards



Tony


cap10bill
Mega Contributor

I'm having issues getting the Date filter to work with the table api



Example I've tried all return 20 rows without ANY filtering using Postman (I have older date than I want)



https://<MyInstance>/api/now/table/cmdb_rel_ci?sysparm_query=sys_update_on>'2015-01-01%3223:59::59'&sysparm_limit=20&sysparm_offset=0



https://<MyInstance>/api/now/table/cmdb_rel_ci?sysparm_query=sys_update_on>=javascript:gs.dateGenerate('2015-01-01','00:00')&sysparm_limit=20&sysparm_offset=0