Get the oldest incident

Arely
Tera Contributor

Hi all,

 

I'm trying to obtain the oldest ticket to show the age in a single score in a dashboard

 

This is the script that I have:

 

function getOldIncident (){
var glideIncident = new GlideRecord('incident');
glideIncident.addQuery('state',1);
glideIncident.orderBy('sys_created_on');
glideIncident.setLimit(1);
glideIncident.query();
var number='';
if(glideIncident.next()){    
number=glideIncident.getValue('number');
}

return number;
}
 
and this is how I applied in the report and also the result that I obtained...
Arely_0-1726012992557.png

 

 I already tried with this other script but I didnt obtain any result
function getOldIncidentTest (){
    var glideIncident = new GlideRecord('incident');
    glideIncident.addQuery('state',1);
    glideIncident.orderBy('sys_created_on');
    glideIncident.setLimit(1);
    glideIncident.query();
    var number='';
    if(glideIncident.next()){    
        var incidentDate = new GlideDateTime();
        incidentDate.setValue(glideIncident.sys_created_on);
        var dur = new GlideDuration();
        dur = GlideDateTime.subtract(incidentDate, new GlideDateTime());

    }

    return dur;
}
2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Is the incident shown the correct or incorrect oldest incident in the New state? What are you expecting to see?

Yes I already got the oldest incident but I want to show only the age of the oldest incident in a single score to add in a dashboard.