Ticket age calculation

catchdini
Tera Expert

I created a business rule (on display) for incidents, to calculate the age. Below is the BR that I used. I created 2 fields - Age and Current Date(though I didn't use this for calculation). Current Date is obtained by a BR (on display) with the script current.u_current_date = gs.nowDateTime();

 

I have included 2 var in the script, where one is commented. If the current date field is utilized then one can make use of the commented var. If current date field is not utilized, then one can use the other var.

 

calculateAge();

function calculateAge(){

var datedif = gs.dateDiff(current.sys_created_on,gs.nowDateTime());

//var datedif = gs.dateDiff(current.sys_created_on,current.u_current_date);

current.u_age = datedif;

current.update();

}

 

find_real_file.png

 

Though Im seeing the Age, Im not sure how the difference (not sure which time zone is utilized ) is calculated. Hope this is the answer for everyone who wanted to calculate the age. If there is anything wrong in the calculation, please let me know.

13 REPLIES 13

Armacar
Tera Contributor

Hi Guys,



Just to help anyone interested on this topic, I had a HUGE issue configuring this BR (Business Rule) on my production enviroment, here's the steps I followed:



  1. I created a field over my incident table called "age" (it automaticly saved as "string" type).
  2. I created the BR with the script on top with the modified line proposed by :

find_real_file.png


find_real_file.png



  3. As you can see There's other fields that are important to mention what to do with, as "when to run", I selected "display" so I could have real time age when looking to any ticket and checked the box "Query" to have age updated on each query.



  4. Everything was working beautiful, I was able to acces to any ticket and perfom any update to give the age of all the tickets but here's what happend: SERVICE DESK started to have the following error while creating tickets (red lines):



find_real_file.png



At the moment of saving the incident the INC number was displayed BUT it was actually NOT inserted on the Incident Table. I had to quickly disabled the rule because this error.



BE CAREFUL WHILE PERFORM THIS BR, I COULD NOT RESOLVE THE ISSUE.


Hi Armando ,



I think this issue is coming because of current.update() line in script. current.update shouldn't be used before any update made on Incident table.



I think if we add the condition


!(current.isNewRecord()) in the BR, it wouldn't run for the new Incidents which are not created yet.



But I am not sure if this is the optimal solution, for this issue.


Hi harshvardhanjoshi, 

 

I'm new of this tool and I too have same requirement as I need to add Age filed in Incident/Req/Task forms. 

I added all above said code and added your code too.. but still I'm getting error what armacar said.

Could you please let me know where can I add your code {!(current.isNewRecord())} in the above code.

 

Thank you in Advanced!!!!!!

 

------Chinna

venkeyk
Tera Contributor

Hey Armacar, Have you got solution for the above query? If yes please let me know ---Chinna