Has anyone written a business rule to calculate time spent on an incedent, I've tried to create a rule that subtracts the start date from the closed date but have had no luck. Just hoping someone has done this.

Field name: Open Time (minutes)
Operation: Calculate
Value: DATEDIFF("Minute",%[Created]%,%[Completed]%)

Of course you may have to build in some more criteria to make sure things are as you want them, for instance maybe if you don't want the Open Time field to be repopulated you'd make sure it was blank, etc.

Either way, the open time field will be populated with the number of minutes between the two dates.

pille wrote:Probably the easiest way to do this is by using DateDiff and some UDFs. For instance here's an example...let's measure the time between the Created date and the Completed Date.

- create an Incident UDF called 'Open Time (minutes)', make it an integer- create an Incident business rule

Event: Before Object is savedCriteria: Completed Date is not blankAction: Update Fields

Field name: Open Time (minutes)Operation: CalculateValue: DATEDIFF("Minute",%[Created]%,%[Completed]%)

Of course you may have to build in some more criteria to make sure things are as you want them, for instance maybe if you don't want the Open Time field to be repopulated you'd make sure it was blank, etc.

Either way, the open time field will be populated with the number of minutes between the two dates.

Hi, Thanks for this helpful tip. Just onething, How can I calculate this field for open tickets also? For example, the incident is still open and calculate the open minutes by comparing created date and current datetime if the COMPLETED date is blank (means open). If the completed date present, then calculate as you mentioned in quote.

For AN5, you'd have to have two separate triggers. One would work on certain statuses when the completed date exists and the other would work on certain statuses when the completed date does not exist.

For instance, one rule would check to see if the status is not resolved or closed and the other needs to check for open statuses.

Then just use the datediff approach, but use the system macro for NOW. Something like this: