Add two duration fields together and populate custom field with calculation BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 09:22 AM
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 🙂
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 09:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 12:27 PM
That doesn't seem to be working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2019 08:25 AM
Can anyone help please? thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2019 10:46 AM
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