- 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-10-2025 12:40 AM
@Deepika54 Give try using this:
var slaGr = new GlideRecord('contract_sla');
if (slaGr.get('sys_id', 'PUT_YOUR_SLA_SYS_ID_HERE')) {
var seconds = 43200; // Ex.: 12 hours
var duration = new GlideDuration();
duration.setValue(seconds * 1000); // GlideDuration expects milliseconds
slaGr.setValue('duration', duration);
slaGr.update();
}
✔️ If this solves your issue, please mark it as Correct.
✔️ If you found it helpful, please mark it as Helpful.
—
Shubham Jain