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

Community Alums
Not applicable

Hello @Harish KM 

Upon update still not working, and i found another issue when i creating new incident it will appear above 30 days and the older incidents are still nothing appears to the incident age field.

Hi @Community Alums Create a new incident and can you check in logs table what value it prints. the below one.

gs.info('Incident age in days: ' + days);

Regards
Harish

Community Alums
Not applicable

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

Community Alums
Not applicable

Hello @Harish KM 

Works now thanks for the help!