
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 12:08 AM - edited 01-13-2023 12:10 AM
Hello Team,
I Have created one background script to insert SLA definition record in 'contract_sla' table.
I am able to create a record in said table but I need a code to set duration value.
So, could you please help me with the script to convert String value (5 Hrs.) to Duration value in SLA Definition Table.
For example :
Resolution Time : 5 (Value is in Hrs)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 12:28 AM
You can create a GlideDuration object by below function ,
but you should format your string to the right format(d HH:mm:ss) <-- i think this is not a problem for you.
GlideDuration(String displayValue)
displayValue | String | Duration value. Format: d HH:mm:ss where "d" is number of days. |
var duration = new GlideDuration('3 12:00:00');
var duration2 = new GlideDuration('3:00:00');
var answer = duration.add(duration2);
gs.info(answer.getDisplayValue());
output
3 Days 15 Hours
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 12:20 AM
Hello @Akshay Harkulka ,
Please find the below code.
s2t=function (t){
var duration= parseInt(t/86400)+'d '+(new Date(t%86400*1000)).toUTCString().replace(/.*(\d{2}):(\d{2}):(\d{2}).*/, "$1h $2m $3s");
gs.print(duration);
return duration;
}
s2t(1236768);
*** Script: 14d 07h 32m 48s
you can pass the string value in s2t (stringoutput)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 05:27 AM
Thanks @Omkar Kumbhar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 12:28 AM
You can create a GlideDuration object by below function ,
but you should format your string to the right format(d HH:mm:ss) <-- i think this is not a problem for you.
GlideDuration(String displayValue)
displayValue | String | Duration value. Format: d HH:mm:ss where "d" is number of days. |
var duration = new GlideDuration('3 12:00:00');
var duration2 = new GlideDuration('3:00:00');
var answer = duration.add(duration2);
gs.info(answer.getDisplayValue());
output
3 Days 15 Hours

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 05:27 AM
Thanks @newhand