Step 1: Create New field on incident table – u_aging_category
Step 2: Write scheduled job run daily to update incident age.
updateIncidentAging(); function updateIncidentAging() { var elapsedTime = 0; var age = ''; var currentTimeNow = gs.nowDateTime(); var gr = new GlideRecord('incident'); gr.addEncodedQuery('u_aging_category!=>28^ORu_aging_category='); gr.query(); while(gr.next()) { elapsedTime = (gs.dateDiff(gr.opened_at, currentTimeNow, true))/60/60/24; // Check to see when the item was created if (elapsedTime <= 2) aging = '0-2 Days'; if (elapsedTime > 2) aging = '3-7 Days'; if (elapsedTime > 7) aging = '8-14 Days'; if (elapsedTime > 14) aging = '15-21 Days'; if (elapsedTime > 21) aging = '22-28 Days'; if (elapsedTime > 28) aging = '> 28 Days'; gr.setWorkflow(false); // Skip any Business Rules gr.autoSysFields(false); // Do not update system fields gr.u_aging_category = age; gr.update(); } }
Output
0
1:
2:
3
How to Create Incident Aging Report base on Priority ServiceNow
Working Code Edited question July 19, 2023