REST API and Timezones

efindley
Giga Contributor

I have been experimenting with the REST APIs and Date/Time fields.   I am POSTing to an Import Set and then GETing from the corresponding table.   When we post, we are posting all Date/Times in 'GMT', but for the longest time I couldn't figure out why I wasn't getting the expected date when I was retrieving the record.   I finally discovered documentation that said that the dates are returned using the user's timezone that was used in the REST call. Sure enough, setting my test user's timezone finally meant that I could retrieve the same date that I posted.  

However, I am trying to develop a consumer of these REST calls that doesn't know about the user in service now. Is there a way to programmatically ask for the dates in 'GMT' or in a format that includes the timezone so that I can normalize it in our code?   It seems very odd that my backend application should have to know anything about the service now user's account other than the fact that it is authorized to make the calls and access the data. Or is there some other way to handle date/times when using REST?

Thanks for your help.

8 REPLIES 8

::sigh:: and as an addendum, something seems to be buggy here even more than the unknown transform happening on import.   This morning, when I was testing with the user's timezone set to GMT, it was getting imported as exactly 12 hours ago.   Now (3 hours later), having the user's timezone set to GMT imports the GMT date correctly.  


You can do a transform map script that takes the value, casts into whatever timezone you want, then sets that answer.   Either Field map script of transform map script would work:


Transform Map Scripts - ServiceNow Wiki


Creating New Transform Maps - ServiceNow Wiki


venkata_koya
ServiceNow Employee
ServiceNow Employee

When date time values are sent using ServiceNow REST APIs, they are treated as GMT values and are put in db as is. when retrieving as well, dates are returned as is. The problem is with transform process. When trying to transform, transformer retrieves date time in user time zone and set it as if it is GMT.


Are you using field map to map source to target.



To work around, you can send data into import set with query parameter "sysparm_input_display_value" on REST API, which will set data time as user time zone in import set and during transform it will work as expected


The parameter "sysparm_input_display_value" doesn't works here. My request returns with json error. Some body help me, please!