How to calculate the On hold time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 10:24 PM
Need to calculate the onhold time for a particular task. So I created a field 'On hold time' which contain the time when the ticket got onhold. So my plan is to get the difference of onhold time and current updated time, so I can populate the value on Total On-hold time.
So I wrote a before business rule with condition State changes from On hold.
(function executeRule(current, previous /*null when async*/ ) {
var thold=current.u_total_on_hold_time;
if (previous.u_on_hold_time.getDisplayValue() != current.u_on_hold_time.getDisplayValue()) {
var onhold = new GlideDateTime(current.u_on_hold_time);
var time = new GlideDateTime(gs.nowDateTime());
var diff = GlideDateTime.subtract(onhold, time);
var date = diff.getRoundedDayPart();
var udate = thold+date;
current.u_total_on_hold_time = udate;
current.update();
}
})(current, previous);
These are the field details.
Please help me to do this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 04:44 AM
Is the above code working ?