Page 1 of 1

Business Rule Creation to Calculate Time Spent

PostPosted: Wed Jun 20, 2007 2:07 pm
by SitusIT
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.

Thanks.

PostPosted: Mon Jun 25, 2007 11:15 am
by pille
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 saved
Criteria: Completed Date is not blank
Action: Update Fields

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.

Open Time Field

PostPosted: Tue Apr 22, 2008 6:15 am
by lina_eleraky
how can i populate the Open Time Field with something else other than minutes??

Re: Open Time Field

PostPosted: Tue Apr 22, 2008 9:29 am
by pille
lina_eleraky wrote:how can i populate the Open Time Field with something else other than minutes??


Check out this link - http://msdn2.microsoft.com/en-us/library/ms189794.aspx

It will give you information on the parameters that DATEDIFF allows.

Re:

PostPosted: Sat Jun 11, 2011 6:36 am
by basheer
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 saved
Criteria: Completed Date is not blank
Action: Update Fields

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.


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.

How can i achieve this?

Thanks for your help

Re: Business Rule Creation to Calculate Time Spent

PostPosted: Mon Jun 13, 2011 9:32 am
by pille
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:

Value: DATEDIFF("Minute",%[Created]%,<NOW>)