To calculate age of an incident i have tried below process it is working fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 02:58 PM - edited 01-03-2024 08:26 AM
To calculate age of an incident even if it is not in resolved state, we can create a field "incident age" of duration type and calculate using the below code.
step 1: Create a field "incident age" of Duration type
step 2: open the dictionary of the field and apply below code in "calculated value" tab
#servicenowcommunity #incidentage
Please mark helpful if it is useful.
- 971 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 09:45 PM
Hello @Ranjith95 ,
Please try below code:
var grIncident = new GlideRecord('incident');
if (grIncident.get('552c48888c033300964f4932b03eb092')) {
var checkDate1 = grIncident.getValue('opened_at'); // update your field name here as - gr.opened_at
var checkDate2 = new GlideDateTime(checkDate1);
var gdt2 = new GlideDateTime(); // returns current date and time
var statusDate = checkDate2.getDate();
var currentDate = gdt2.getDate();
var diff = new GlideDateTime.subtract(statusDate, currentDate);
var days = diff.getDayPart();
gs.info(days);
}
Mark my correct and helpful, if it is helpful and please hit the thumbs-up button to mark it as the correct solution.
Thanks & Regards,
Pratiksha Kadam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 09:57 PM
We have some OOTB SLA's field that can be utilize instead of creating new one
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 11:03 PM
Helpful