how to change duration type field value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2025 02:30 AM
Hi everyone,
I am getting Business left time value in this format :
1970-01-23 09:48:26
but I want to get Business time left values in day's and hours format. please suggest me how to achieve this.
currently I have written this code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2025 02:49 AM
Hi @Star123
Try below scripts.
Option 1:
var gr = new GlideRecord('task_sla');
gr.addQuery('task.number', 'RMSR000010855'); // Query by task number
gr.query();
while (gr.next()) {
gs.info('Business Time Left: ' + gr.business_time_left.getDisplayValue());
}
Option 2:
var gr = new GlideRecord('task_sla');
gr.addQuery('task.number', 'RMSR000010855'); // Query by task number
gr.query();
while (gr.next()) {
gs.info('Business Time Left: ' + gr.business_time_left.getDurationValue());
}
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2025 02:56 AM
hello @Star123
Please refer the below code and make changes accordingly and let me know if anything else
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2025 03:12 AM
this should work for you
var gr = new GlideRecord('task_sla');
gr.addQuery('task.number', 'WO0010097'); // Query by task number
gr.query();
while (gr.next()) {
// Get the business_time_left in seconds
var duration = new GlideDuration(gr.business_time_left.getDurationValue());
var days = parseInt(duration.getNumericValue() / 86400000);
var hour = duration.getByFormat('HH'); //get hour part
var mins = duration.getByFormat('mm'); //get mins
var finalValue = 'Days ' + days + ' Hours ' + hour;
gs.info(finalValue);
}
Record showing the Duration:
Output:
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
05-10-2025 11:16 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