Date format in rest API response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 06:02 AM
API: Aggregated table
Table: Incident_SLA
When I return 'inc_opened_a', is it possible to format the date differently in the query?
Current format: yyyy-mm-dd hh:mm:ss
Preferred format: yy-mm-dd
Reason is, that I would like to aggregate and response based on date, and not date + time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 05:51 PM
Hi Joakim,
I don't think there's any way to change the date format that comes back in the REST API response. Instead it should be simple to use a regex to extract the parts of the date string that you want, for example:
var inc_opened_at = "2015-11-10 23:44:21";
var yymmdd = inc_opened_at.match(/\d{2}-\d{2}-\d{2}/);
gs.print(yymmdd);
This gives the output: 15-11-10
Please try it and let me know if that helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2017 01:10 AM
Hello Tim,
I am familiar with javascript but yet to learn how to do the above in servicenow, care to elaborate?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2017 09:51 PM
Hi Joakim,
As far as I can see you can't change the date/time format that comes through in JSON data from the REST API. That means you need to do the date/time format conversion (from yyyy-mm-dd hh:mm:ss to yy-mm-dd) in whatever program or script you're using to make the REST API calls.
I gave an example in Javascript since that's the most commonly used scripting language with ServiceNow, but you could easily do the same in Python, Ruby or whatever else you're using to process the data from the REST API calls.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 12:27 AM
Ok sure, I see what you mean now. The only problem with that is that I will get one response per timestamp, which might be a lot of data in the end. This is why I was hoping to use the aggregated API to tidy things up.