Calculate duration for "Days Open"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2013 08:59 AM
Hello, I have created a duration field called "Days Open" which I would like to have reflect the total amount of time (in Days) elapsed between between the Opened date and Current date.
I know this has got to be very simple to do so I was looking at the "Duration" field to use as an example, but I haven't been able to find where the code is entered for the calculation. ??
Thanks in advance for any help you can provide. 🙂
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2013 09:36 AM
Here is a script include I have developed for duration calculations, called "CalculateDuration":
gs.include("PrototypeServer");
var CalculateDuration = Class.create();
CalculateDuration.prototype = {
calculate_duration : function(start,end) {
var duration = {};
duration.duration = gs.dateDiff(start,end,false);
duration.seconds = gs.dateDiff(start,end,true);
if (duration.seconds < 0) {
duration.seconds = 0;
}
duration.days = parseInt(duration.seconds * 100 / 86400,10)/100;
return duration;
}
};
This returns an object with three parameters:
obj.duration = a glide duration
obj.seconds = the difference in seconds between start and end.
obj.days = the difference in days between start and end.
It is important to know what time zone you are using for both start and end values so that you get the expected result.
So here is an example where I calculate the duration of a task:
var start = current.sys_created_on.getDisplayValue();
var end = current.work_end.getDisplayValue();
var td = new CalculateDuration();
var duration = td.calculate_duration(start,end);
current.u_task_duration = duration.duration;
current.u_task_duration_in_days = duration.days;
If this helps, please mark this question as "answered." Thanks!
Cheers,
Geoff.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2013 09:40 AM
Thanks for the info, Geoff. I see where the script include is setup under System Definitions, but where does the calculation take place (or how is the script include called/triggered to calculate a duration)? If I go into Personalize Dictionary on the newly created field, I see a 'Calculated' check box and a 'Calculation' field, but it doesn't appear this is where the contents of your calculation example would go.
Again, thanks in advance for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2013 10:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2013 12:50 PM
Please remember to mark your question as answered. Thanks!