- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2019 11:17 AM
Hi,
I want to convert a Duration field (days:hours:minutes:seconds) like next to hours.
The field is like this picture
Somebody could help me with that,please?
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2021 12:11 PM
For anyone else struggling with a similar issue, here's the code I used to add the time in a duration field to the start date/time and then populate the end date/time via a before insert/update business rule.
Converting the duration field to a GlideDateTime and then using the .getValue() function was crucial. Next you have to use the getNumericValue to get the time in milliseconds. From there you can manipulate the integer values from there and hopefully get what you're looking for...
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
// calculates the end time of an activity based on the start time and duration
var startTime = new GlideDateTime(current.variables.access_start.getValue()); // getting start time
var dur = new GlideDateTime(current.variables.how_long.getValue()); // getting duration and converting to GlideDateTime
dur = dur.getNumericValue()/1000; // calculating the total duration in seconds
//gs.addInfoMessage(dur);
startTime.addSeconds(dur); // add the seconds to the start time to calculate end time
current.variables.access_end = startTime.getValue(); // set the end time
gs.addInfoMessage("End time automatically adjusted based on start time and duration");
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2019 01:17 PM
Hi asifnoor,
I did it last week but it does't work in Madrid version.
Thanks for your answer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2019 08:26 AM
Hi,
Could you let me know the issue that you are facing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2021 12:11 PM
For anyone else struggling with a similar issue, here's the code I used to add the time in a duration field to the start date/time and then populate the end date/time via a before insert/update business rule.
Converting the duration field to a GlideDateTime and then using the .getValue() function was crucial. Next you have to use the getNumericValue to get the time in milliseconds. From there you can manipulate the integer values from there and hopefully get what you're looking for...
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
// calculates the end time of an activity based on the start time and duration
var startTime = new GlideDateTime(current.variables.access_start.getValue()); // getting start time
var dur = new GlideDateTime(current.variables.how_long.getValue()); // getting duration and converting to GlideDateTime
dur = dur.getNumericValue()/1000; // calculating the total duration in seconds
//gs.addInfoMessage(dur);
startTime.addSeconds(dur); // add the seconds to the start time to calculate end time
current.variables.access_end = startTime.getValue(); // set the end time
gs.addInfoMessage("End time automatically adjusted based on start time and duration");
})(current, previous);