Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(function executeRule(current, previous /*null when async*/ ) {

/*
Inputs
1. Opened(opened_at)
2. Resolved(resolved_at)

Checks & Validation
1. It will check the Date/Time validation whether it Resolved time should be greater than Open time
2. And it will not calculate the empty values

Outputs
1. If everthing has a right value like the Opened < Resolve Date/Time then Duration will be calculated and populated in the respective field
2. Negative case if Opened > Resolved the duration will not calculate and it will Abort the action to save the record with Error message.
*/

// Getting both the date from the record
var opened = GlideDateTime(current.opened_at.getDisplayValue());
var resolved = GlideDateTime(current.resolved_at.getDisplayValue());

//If the opened and resolved times are present, calculate the duration
if (opened && resolved) {
var difference = GlideDateTime.subtract(opened, resolved);
if (difference.getYearUTC() >= 1970)
current.calendar_duration.setValue(difference);
else {
current.calendar_duration.setValue(null);
current.resolved_at.setValue(null);
current.setAbortAction(true);
gs.addErrorMessage("Incident Resolve date/time must be greater than incident Opened date/time");
}
}



})(current, previous);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Calculate Incident Duration and Validation.

Script Type : Business Rule Trigger: before update Table: incident Condition: Resolved Changes or Opened Changes

Goal : To calculate the duration of a particular record and how much time has been spent on a particular ticket.

Walk through of code :
So when the Resolved Changes or Opened Changes in a particular record to calculate the duration will this Business rule will pull those values
And then check whether the Opened Data/Time is lesser than the Resolved Date/Time the will calculate the duration
Else it will throw the Error Message and then Abort that action and won't save the record and will clear the values.

Loading