Handling Duration fields in API response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 2 weeks ago
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 !
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
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.
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
Option 3
PS : In the above examples, I have used incident_alert table which has two duration fields
Let me know your feedback !