How to get incident age

Community Alums
Not applicable

Hello,

I have a requirement regarding getting the incident aged based on the created date, incident age will appear in the choice list if incident new will appear (Below 30 days) if the incident above 30 days (Above 30 days) and (Above 60 days) until (Above 90 days).

1 ACCEPTED SOLUTION

Hi @Community Alums I amended few changes,

Change your BR trigger to before insert/update and remove current.update from script.

 

Script:

var days;
var createdAt= new GlideDateTime(current.sys_created_on); //get the incident opened_at date
var now = new GlideDateTime(); //get the current date and time
var duration = gs.dateDiff(createdAt, now, true); //calculate the difference
days = parseInt(Math.floor(duration / 86400)); //convert the duration to days
gs.info('Incident age in days: ' + days);
if(days <= 30)
{
current.u_incident_time= 'below_30';
}
if(days > 30 && days <= 60) // there was error here i was using < 30 hence going to this condition made it to > 30
{
current.u_incident_time= 'above_30';
}
if(days > 60)
{
current.u_incident_time= 'above_60';
}
 
HarishKM_0-1709708961640.png

 

Regards
Harish

View solution in original post

27 REPLIES 27

Aman Kumar S
Kilo Patron

I would suggest not to go this way, why would you want to run a BR every time there is an update just to calculate the time, rather you bring the created field on the form layout and set user preference, so that by hovering on the date it will show how many days ago it was created.

 

Best Regards
Aman Kumar

Community Alums
Not applicable

Hello @Aman Kumar S 

Can you show me? thanks!

You have this user preference which you can set in user preference table:

AmanKumarS_0-1709706856915.png

AmanKumarS_1-1709706933066.png

 

Best Regards
Aman Kumar