How to Query Based on Displayed Date Values in ServiceNow Table API (Considering User Time Zone)?

lucky6
Tera Contributor

Hi everyone,

I’m trying to query records from a specific date range using the ServiceNow Table API. When I use the query from the list view, it includes a JavaScript function like:

 

javascript:gs.dateGenerate('2024-10-05', '05:40:02')@javascript:gs.dateGenerate('2024-10-06', '05:06:04')

 

However, I need to convert this to a format that works for a third-party API call. I’ve tried using the BETWEEN operator with the date values, but the query seems to be checking the UTC format instead of the displayed values in the user’s time zone.

 

Is there a way to query based on the display values (local time zone)?

Thanks in advance..

3 REPLIES 3

Niklas Peterson
Mega Sage
Mega Sage

Hi @lucky6 ,

 

In my opinion you should use UTC for your query. That's the best way that the third party system can make API calls consistantly. If you would pick up data based on user time zone you would never know what results you get. If you need time zone conversion then it should happen on the third party side before querying so that the query can be done using UTC.

 

Regards,
Niklas

Hi @Niklas Peterson ,

 

Thank you for the response..here users login data is in Eastern timezone.. without UTC timezone is it not possible to retrieve the data based on the list view?

Hi @lucky6 ,

 

Inside the plattform date and time are visualized to the users with the help of Time Zones so that the date and time makes sense to the user. However the record doesn't store all that information. It stores the date and time in the time zone of the system, which default is UTC. In a third party integration call you would query for the date and time stored on the record which could be different than what the users see.

Which means your third part api calls need to know what time zone to use.

 

Regards,
Niklas