- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 02:00 AM
Does anyone have a business rule I can use as an example to convert the duration between 2 dates to minutes?
We currently have 2 date fields (dd/mm/yyyy hh:mm:ss)
u_outage_start
u_outage_end
Looking to get this converted to minutes in field u_reported_downtime_degradation
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 03:17 AM
Yes,
That is because you are setting the seconds variable and not mins, Use the below
(function executeRule(current, previous /*null when async*/) {
var dateString1 = new GlideDateTime(current.u_outage_start);
var dateString2 = new GlideDateTime(current.u_outage_end);
var diffSeconds = gs.dateDiff(dateString1, dateString2, true);
diffMins = diffSeconds/60;
current.u_reported_downtime_degradation = diffMins ;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 02:12 AM
Hi,
Try this
var dateString1 = new GlideDateTime(current.u_outage_start);
var dateString2 = new GlideDateTime(current.u_outage_end);
var diffSeconds = gs.dateDiff(dateString1, dateString2, true);
diffMins = diffSeconds/60;
return Math.round(diffMins); // return the calculated value
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 02:21 AM
Hi, is this a calculated value? I ideally need this as a business rule if possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 02:57 AM
The same script would run in a BR as well, just instead of return you set it to the field you want.
The BR should run when both begin and end fields have values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 03:07 AM
Brilliant! Thanks for your help I used this in the end.
(function executeRule(current, previous /*null when async*/) {
var dateString1 = new GlideDateTime(current.u_outage_start);
var dateString2 = new GlideDateTime(current.u_outage_end);
var diffSeconds = gs.dateDiff(dateString1, dateString2, true);
diffMins = diffSeconds/60;
current.u_reported_downtime_degradation = diffSeconds;
})(current, previous);