Skip to content

Commit 02ea335

Browse files
authored
Calculate Incident Duration/Validation (#2194)
1 parent 48e315a commit 02ea335

File tree

2 files changed

+47
-0
lines changed
  • Server-Side Components/Business Rules/Calculate Incident Duration and Validation

2 files changed

+47
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(function executeRule(current, previous /*null when async*/ ) {
2+
3+
/*
4+
Inputs
5+
1. Opened(opened_at)
6+
2. Resolved(resolved_at)
7+
8+
Checks & Validation
9+
1. It will check the Date/Time validation whether it Resolved time should be greater than Open time
10+
2. And it will not calculate the empty values
11+
12+
Outputs
13+
1. If everthing has a right value like the Opened < Resolve Date/Time then Duration will be calculated and populated in the respective field
14+
2. Negative case if Opened > Resolved the duration will not calculate and it will Abort the action to save the record with Error message.
15+
*/
16+
17+
// Getting both the date from the record
18+
var opened = GlideDateTime(current.opened_at.getDisplayValue());
19+
var resolved = GlideDateTime(current.resolved_at.getDisplayValue());
20+
21+
//If the opened and resolved times are present, calculate the duration
22+
if (opened && resolved) {
23+
var difference = GlideDateTime.subtract(opened, resolved);
24+
if (difference.getYearUTC() >= 1970)
25+
current.calendar_duration.setValue(difference);
26+
else {
27+
current.calendar_duration.setValue(null);
28+
current.resolved_at.setValue(null);
29+
current.setAbortAction(true);
30+
gs.addErrorMessage("Incident Resolve date/time must be greater than incident Opened date/time");
31+
}
32+
}
33+
34+
35+
36+
})(current, previous);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Calculate Incident Duration and Validation.
2+
3+
Script Type : Business Rule Trigger: before update Table: incident Condition: Resolved Changes or Opened Changes
4+
5+
Goal : To calculate the duration of a particular record and how much time has been spent on a particular ticket.
6+
7+
Walk through of code :
8+
So when the Resolved Changes or Opened Changes in a particular record to calculate the duration will this Business rule will pull those values
9+
And then check whether the Opened Data/Time is lesser than the Resolved Date/Time the will calculate the duration
10+
Else it will throw the Error Message and then Abort that action and won't save the record and will clear the values.
11+

0 commit comments

Comments
 (0)