
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2022 11:07 AM
Hi Team,
I need to set below value in glide_duration type field. Please let me know how to set this value into Duration field:
Time = 100 (minutes)
How to set this 100 mins into Duration field.
I tried like below, but, the vaqlue is not set into duration field.
current.time_worked = new GlideDuration('100');
Please suggest and provide proper way/script to set minutes value into Duration field.
Thanks & Regards,
Prasanna Kumar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 09:55 AM
the following worked for me, I created a new field on my table with type 'glide_time'.
var xTable = new GlideRecord('x_snc_bctestappnew_app_table');
xTable.query();
while (xTable.next()) {
gs.info("u_time = " + xTable.u_time + ".");
}
//new record
var numMinutes = 100;
var minutes = numMinutes%60;
var hours = (numMinutes - minutes)/60;
var timeVal = "1970-01-01 " + hours.toString() + ":" + minutes.toString() + ":00";
gs.info("timeVal = " + timeVal + ".");
xTable.initialize();
xTable.u_time = timeVal;
xTable.u_name = "New record";
xTable.insert();
you need extra logic if your value of minutes that you start with is greater than 1440 (one day).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2022 12:27 PM
And duration fields are the number of seconds from 1970-01-01 00:00:00.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 01:42 AM - edited 11-28-2022 01:50 AM
Hi @Bert_c1 ,
After getting hours and minutes, how to set these values to glide_time field?
var numMinutes = time; (here time=100)
var minutes = numMinutes%60;gs.print("minutes: "+minutes);
var hours = (numMinutes - minutes)/60; gs.print("hours: "+hours);
In Incident the duration field is "u_aws_time_worked"
So,
var fin = new GlideDuration('0 '+hours+':'+minutes+':00');
inc.u_aws_time_worked = fin;
inc.update();
Out Put:
*** Script: minutes: 40
*** Script: hours: 1
*** Script: numMinutes = 100 = 1 hours and 40 minutes.
*** Script: 1970-01-01 01:40:00
But, nothing updated in that field. Showing like below:
Please let me know how to update the resulting converting time into duration field.
Thanks you so much for your help in advance.
Thanks & Regards,
Prasanna Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 05:36 AM
The field type should be "glide_duration" and not "glide_time"
var durStart = new GlideDateTime(gs.nowDateTime());
var durEnd = new GlideDateTime(gs.nowDateTime());
gs.print(durStart);
durEnd.addSeconds(6000); //From your calc minutes expressed as seconds 30 min * 60 sec = 1800 sec
gs.print(durEnd);
var duration = GlideDateTime.subtract(durStart, durEnd);
gs.print(duration.getDisplayValue());
var recGR = new GlideRecord("incident");
if(recGR.get("56c13d722fd230104fce5d492799b676")){
recGR.u_aws_time_duration = duration;
recGR.update();
}
Vinod Kumar Kachineni
Community Rising Star 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 05:46 AM
Hi Vinod,
Actually, it is showing Glide_time only. It's Time type field. not Duration type field.
So, I can't able to set the value to that field.
Thanks & Regards,
Prasanna Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 09:55 AM
the following worked for me, I created a new field on my table with type 'glide_time'.
var xTable = new GlideRecord('x_snc_bctestappnew_app_table');
xTable.query();
while (xTable.next()) {
gs.info("u_time = " + xTable.u_time + ".");
}
//new record
var numMinutes = 100;
var minutes = numMinutes%60;
var hours = (numMinutes - minutes)/60;
var timeVal = "1970-01-01 " + hours.toString() + ":" + minutes.toString() + ":00";
gs.info("timeVal = " + timeVal + ".");
xTable.initialize();
xTable.u_time = timeVal;
xTable.u_name = "New record";
xTable.insert();
you need extra logic if your value of minutes that you start with is greater than 1440 (one day).