Incident Report should include Incident aging

Priya madyapgol
Tera Contributor

Hi Team, 

 

I have one requirement on Incident Reports,

Incident reports should have Incident age,

for that i have created one custom field on Incident table i.e, Incident age(String field), and have written one Async Business Rule.

calculateAge();
    function calculateAge(){
       
        var datedif = gs.dateDiff(current.sys_created_on.getDisplayValue(),gs.nowDateTime,false);

        current.u_incident_age = datedif;
        current.update();
       
    }
 
but which is not working properly,
when i create new incident records, the custom field is updating as below attached snapshot, but after some time also the time is not changing.
 
Priyamadyapgol_0-1745302750759.png


Please help me to get the solution asap.

Thanks,

1 ACCEPTED SOLUTION

@Priya madyapgol 

if you want age to be seen irrespective of update then use calculated field for that and add the calculation there

so whenever list is opened the field will be calculated and age will be seen

Don't use BR then

AnkurBawiskar_0-1745308576784.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

@Priya madyapgol 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Priya madyapgol 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Priya madyapgol 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

J Siva
Tera Sage

Hi @Priya madyapgol 

I'm not sure how you configured that on your end, but I've tried the script below in my PDI, and it's working as expected. Please find it below.

(function calculatedFieldValue(current) {

    // Add your code here
    var created = new GlideDateTime(current.getValue('sys_created_on'));
    var today = new GlideDateTime();
    var dur = GlideDateTime.subtract(created, today); 
    return dur.getDisplayValue();

})(current);

 

JSiva_0-1745386348944.png

 

Output:

JSiva_1-1745386348848.png

 

 

Regards,
Siva