Populate Business hours difference between two date/time fields into a duration field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 10:02 AM - edited 02-21-2023 12:01 PM
I have two date/time fields in story table and I need to populate difference between those two fields as duration in Actual effort on story table. I am using below script , but I getting slight difference in duration calculation
(function executeRule(current, previous /*null when async*/ ) {
var start = new GlideDateTime(current.u_wip_start_time.getDisplayValue());
var end = new GlideDateTime(current.u_story_dev_end_time.getDisplayValue());
gs.log("check Startdate"+start);
gs.log("check Enddate"+end);
var schedule=new GlideSchedule('090eecae0a0a0b260077e1dfa71da828', 'Canada/Eastern'); //sys_id of 9-5 schedule
var duration = schedule.duration(start, end);
var businesshours = duration.getNumericValue()/3600000 ;
var actualeffort = duration.getDurationValue();
current.work_effort = actualeffort;
current.story_points = Math.round(businesshours);
current.update();
})(current, previous);
Startdate2023-02-15 16:29:34 Enddate2023-02-21 10:32:05 Expected =26 hrs Actual =30hrs
Startdate2023-02-20 14:37:48 Enddate2023-02-21 10:38:36 Expected =5hrs Actual =7hrs
Startdate2023-02-21 09:00:00 Enddate2023-02-21 10:42:04 Expected =1.5-2 hrs Actual =0
Startdate2023-02-20 15:44:18 Enddate2023-02-21 10:45:15 Expected =4 hrs Actual =6

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 10:31 AM
Hi Reddy,
Is this a typo ? 'Canda/Eastern' Make sure you are using 'Canada/Eastern' and that your script run in the same session's timezone.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 10:36 AM - edited 02-21-2023 12:02 PM
Typo Mistake corrected!! Yes I'm using correct time zone only. But still getting same issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 10:02 AM
Any help on this would be much appreciated. I still didn’t find any possible solution