Handling Duration fields in API response

DineshSankar
Tera Contributor

In ServiceNow, the Duration field type is used to store and display time intervals. It represents a period of time, typically calculated as the difference between two date/time values. Duration fields can be formatted to display time in days, hours, minutes, and seconds( Courtesy : Google )

 

When retrieving duration type fields using API, there are three ways to manage it on the consumer side. 

1. Set query parameter sysparm_display_value = true

The values in the response shows in a descriptive user friendly readable format. No confusion !

DineshSankar_0-1755210963539.png

 

2. Set query parameter sysparm_display_value = false(default in SN) 

The values are shown in a date time format, where the value is added to a base date time of 

1970-01-01 00:00:00. In our example for actual disruption time, it adds 4 days 3 hours, 2 minute and 1 second to 1970-01-01 00:00:00, thus showing 1970-01-05 03:02:01. This is useful programmatically, by simply taking the date difference between the response value and 1970-01-01 00:00:00

DineshSankar_1-1755211134092.png

 

3. Set query parameter sysparm_display_value = all

This gives both values, with 'display_value' providing value as per Option 1 above and 'value' providing the value as per Option 2. API consumer can choose which one to go with.

 

DineshSankar_3-1755211728245.png

 

You may notice that the display value in Options 1 and 3 did not contain seconds. So if you need precision up to the seconds, then please refer to KB0719387 . Once the sys property glide.ui.duration.seconds.enabled is set to true, the response will have seconds as well.

Option 1

DineshSankar_5-1755212696635.png

 

Option 3

DineshSankar_4-1755212635302.png

 

PS : In the above examples, I have used incident_alert table which has two duration fields 

estd_disruption_time and actual_disruption_time. Here's how the record shows on the ServiceNow UI.

DineshSankar_6-1755212821039.png

 

Let me know your feedback !

0 REPLIES 0