We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Convert glide duration value to minutes

Sherice1
Tera Contributor

Hello,

We have a field with type duration, but am trying to convert it into minutes and pass value on to string field. tried doing

var duration = current.glidefieldonform.getGlideObject().getNumericValue();
gs.log("minutes"+ duration);

var minutes = (duration/1000/60);

gs.log('duration1' + minutes);
current.fieldtobepopulated = minutes.toFixed();

gs.log('duration' + minutes);

 

 

 

it dont work

please help,

1 ACCEPTED SOLUTION

Dan H
Tera Guru

Hi Sherice,

Try this code:

 var duration = new GlideDateTime(current.glidefieldonform.getValue()); // getting duration and converting to GlideDateTime
    duration = duration.getNumericValue()/1000/60; // calculating the total duration in minutes
    gs.log('Duration in minutes is: ' + duration);
    current.fieldtobepopulated = duration.toString();

Please mark answer as helpful/solved based on impact

View solution in original post

2 REPLIES 2

Dan H
Tera Guru

Hi Sherice,

Try this code:

 var duration = new GlideDateTime(current.glidefieldonform.getValue()); // getting duration and converting to GlideDateTime
    duration = duration.getNumericValue()/1000/60; // calculating the total duration in minutes
    gs.log('Duration in minutes is: ' + duration);
    current.fieldtobepopulated = duration.toString();

Please mark answer as helpful/solved based on impact

sachin_namjoshi
Mega Patron

Use below code

 

var i = new GlideRecord('incident');
i.addQuery('sys_id',"41c01200d7002100b81145a3ce610398");
i.query();
if(i.next()){

var h =  i.business_duration.dateNumericValue()/1000;
var hr = h/3600;
var m = hr*60;
gs.info("Minutes value " + m);

}

 

Regards,

Sachin