File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
Server-Side Components/Business Rules/Calculate Incident Duration and Validation Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments