last six month incident record

shid077
Tera Contributor

how to get the last six month incident record without encoded query??

3 REPLIES 3

pratiksha5
Mega Sage

var incidentGR = new GlideRecord('incident');

var sixMonthsAgo = new GlideDateTime();
sixMonthsAgo.subtract(6 * 30 * 24 * 60 * 60); 

incidentGR.addQuery('sys_created_on', '>=', sixMonthsAgo);

incidentGR.query();

// Loop through the result set and do something with each incident record
while (incidentGR.next()) {
// You can access incident fields using dot notation
var incidentNumber = incidentGR.getValue('number');
var shortDescription = incidentGR.getValue('short_description');

// Do whatever you need to do with the incident data
gs.info("Incident Number: " + incidentNumber + ", Short Description: " + shortDescription);
}

 

Rahul Talreja
Mega Sage
Mega Sage

Hi @shid077 ,
Use,

 

var gr = new GlideRecord('incident');
gr.addQuery('sys_created_on', '>=' , 'javascript:gs.daysAgo(180)');
gr.query();
while(gr.next()){
gs.print(gr.number);
}

 

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Pratiksha_45
Kilo Sage

Hello @shid077 

Please refer following code,

 

var  dateSixMonthAgo= gs.monthsAgo(6);
var grIncident =new GlideRecord('incident');
grIncident.addQuery('sys_created_on', ">=", dateSixMonthAgo);
grIncident.query();
while (grIncident.next()) {
//Add your code
}
 
Please kindly mark as correct/helpful if my solution is useful to you.
Thank you!