REST API to fetch incident updated in last 5 min

Priyanshu
Giga Expert

Hello all,

can anyone help me with the script of rest API to fetch the list of incident updated in last 5 min.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Community Alums
Not applicable
10 REPLIES 10

Hi Cinde,

Then you can try something like this.

Call REST API to fetch the records of last 15 minutes and then store that JSON in a result object.

//sample response
var result = '{"result":[{"number":"INC0010061","sys_updated_on":"2019-07-30 18:14:13"},{"number":"INC0010058","sys_updated_on":"2019-07-30 18:09:30"}]}';

var obj = JSON.parse(result);
var date1 = new Date();
date1.setMinutes(date1.getMinutes()-5);
for(i=0;i<obj.result.length;i++) {
  var date = new Date(obj.result[i].sys_updated_on);
  if(date1 < date) {
    //use these incidents to show in app.
    console.log("True"+obj.result[i].number);
  } 
}

Mark the comment as a correct answer and also helpful if it helps.