Adding two duration fields

hameetkaur
Tera Contributor

I have two duration fields and i want to add the values in those two duration fields and then display the result in hours. How can i achieve it?

3 REPLIES 3

Marco0o1
Tera Sage

Hi @hameetkaur ,

I imagine what do you want to say is, you have for example "Duration 1" field and "Duration 2" field, and you want to have for example "Date Time finish 1" and "Date Time finish 2". Correct me if I'm wrong, you have another field to consider the duration start counting time for example the "created on" field and sum the duration? Can you provide more context about what is you final goal to provide a more help, at the end if what I think is correct you can only create a Business Rule and execute from you reference date and sum the duration of you field to get a final stimated date.

hameetkaur
Tera Contributor

I have 2 fields say 'Duration 1' field and 'Duration 2' field and i want to add both the two fields and display the result in the hour format.

hameetkaur_0-1697226516239.png

 

Hi @hameetkaur 

You need to use getGlideObject().getNumericValue()*0.001/3600 to convert it to hours.

 

Did test for one record in background script as below.

var inci=new GlideRecord('incident');
inci.addQuery('sys_id','9c573169c611228700193229fff72400');
inci.query();
if(inci.next())
{
var dur = inci.calendar_duration.getGlideObject().getNumericValue()*0.001/3600;
gs.print(dur);
}

Result is 

11799.3125

 Apply the same logic of getGlideObject().getNumericValue()*0.001/3600 to convert duration value to hours and then a simple parseInt() or parseFloat() to add the total in hours.