Add two duration fields together and populate custom field with calculation BR

Cheyenne1
Kilo Guru

Good morning, 

I'm trying to add two duration fields together on Incident. 

I have a custom field called u_incident_total_time_worked which is pulling data from the Incident Tasks time worked (total duration spent on all Incident tasks) - working fine. 

I have the OOTB field time_worked on Incident which is required on resolve, at which point on update/save I would like to populate my custom total_time_worked field on Incident. 

 

so basically I want:

total_time_worked = incident_task_total_time_worked + time_worked

 

My before BR looks like this ( but it looks like it's pulling non human time from somewhere) which is triggered when time_worked changes.

 

var inctasktotal = new GlideDuration(current.u_incident_task_total_time_worked).getNumericValue();
var timeworked = new GlideDuration(current.time_worked).getNumericValue();
var total = inctasktotal + timeworked;
var totaltimeworked= new GlideDuration();

totaltimeworked.setNumericValue(total);

current.u_total_time_worked = totaltimeworked.getDurationValue();

 

All help is appreciated 🙂 

7 REPLIES 7

djohnson1
Mega Guru

Cheyennes, 

             I do not believe GlideDuration has a getNumericValue parameter.

Ty this instead:

var inctasktotal = new GlideDuration(current.u_incident_task_total_time_worked).getDurationValue());
var timeworked = new GlideDuration(current.time_worked).getDurationValue();
current.u_total_time_worked = inctasktotal.add(timeworked);

 

Thanks, 

Derrick Johnson

That doesn't seem to be working

Cheyenne1
Kilo Guru

Can anyone help please? thanks!

Cheyennes, 

       My apologies, there was a typo in the code. Please try the below:

 

var inctasktotal = new GlideDuration(current.u_incident_task_total_time_worked).getDurationValue();
var timeworked = new GlideDuration(current.time_worked).getDurationValue();
current.u_total_time_worked = inctasktotal.add(timeworked);

 

Thanks, 

 

Derrick Johnson