- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 08:54 AM
Hello experts,
I am getting a value in seconds. example 43,200 seconds which is 12 hours.
or 86400 seconds which is 1 day.
I need to update 1 day or 12 hours ,i.e these type of values in the duration field of the sla definition table. Kindly help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2025 12:26 AM
ServiceNow's duration fields technically store values in milliseconds behind the scenes, but the GlideDuration object handles the conversion for you when you provide it the correct input.
// Let's say your number of seconds is in a variable called 'secondsValue'
var secondsValue = 43200; // Example: 12 hours
// Convert seconds to milliseconds
var milliseconds = secondsValue * 1000;
// Create a new GlideDuration object using the milliseconds
var duration = new GlideDuration(milliseconds);
// Now, update your SLA Definition record
var slaGr = new GlideRecord('contract_sla'); // Or 'sn_sla_definition' if you're using the new table name
slaGr.get('sys_id_of_your_sla_definition'); // Replace with the actual sys_id of your SLA Definition
slaGr.duration = duration; // Set the duration field
slaGr.update();
gs.info("Updated SLA duration to: " + duration.getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 09:04 AM
to set duration field you can use setDateNumericValue() method
pass milliseconds to it
something like this
gr.u_field.setDateNumericValue(86400000); // pass milliseconds
gr.update();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 11:40 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 03:28 AM
Thank you for marking my response as helpful.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2025 12:26 AM
ServiceNow's duration fields technically store values in milliseconds behind the scenes, but the GlideDuration object handles the conversion for you when you provide it the correct input.
// Let's say your number of seconds is in a variable called 'secondsValue'
var secondsValue = 43200; // Example: 12 hours
// Convert seconds to milliseconds
var milliseconds = secondsValue * 1000;
// Create a new GlideDuration object using the milliseconds
var duration = new GlideDuration(milliseconds);
// Now, update your SLA Definition record
var slaGr = new GlideRecord('contract_sla'); // Or 'sn_sla_definition' if you're using the new table name
slaGr.get('sys_id_of_your_sla_definition'); // Replace with the actual sys_id of your SLA Definition
slaGr.duration = duration; // Set the duration field
slaGr.update();
gs.info("Updated SLA duration to: " + duration.getDisplayValue());