I want list of latest 10 incident records only ?

Abhishek Kathe
Mega Guru
 
9 REPLIES 9

Then @Dan O Connor has already given the correct answer. Please mark it as correct.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Nivedita Patil
Mega Sage
Mega Sage

Hi @Abhishek Kathe ,

 

1. Go to incident module click on open incident.

2. Click on filter.

3. Active is true and add sort z to a . after that run the filter.

4. Go to the form header and right click  and select show > 10 records per page.

 

Please refer the below screenshot.

 

for ans.jpg

 

Mark my answer correct and helpful if helps you.

 

Thanks,

Nivedita Patil.

Eswar Chappa
Mega Sage
Mega Sage

Hi @Abhishek Kathe  with the below script you can get the list of latest 10 incident records

 

// Create a GlideRecord object for the Incident table
var incidentGR = new GlideRecord('incident');

// Order the records by the 'sys_created_on' field in descending order (latest first)
incidentGR.orderByDesc('sys_created_on');

// Limit the query to fetch only the first 10 records
incidentGR.setLimit(10);

// Execute the query
incidentGR.query();

// Iterate through the records
while (incidentGR.next()) {
  // Access and print the fields you need from each record
  var incidentNumber = incidentGR.getValue('number');
  var shortDescription = incidentGR.getValue('short_description');
  
  // Print or process the retrieved data as needed
  gs.info('Incident Number: ' + incidentNumber + ', Short Description: ' + shortDescription);
}

 

 

EswarChappa_0-1695042234713.png

 

Thanks & Regards,

Eswar Chappa

Mark my answer correct and Helpful if this helps you ðŸ˜€

Mohan Mallapu
Kilo Sage

@Abhishek Kathe 

You can achieve it by with below script ways
Background script:  Use the below script to get the latest 10 active records from an incident table.


var gr = new GlideRecord('incident'); 

gr.addQuery('active', true); // Optionally, filter by active incidents
gr.orderByDesc('sys_created_on');
gr.setLimit(10); // Limit the result to the latest 10 records

gr.query();

while (gr.next()) {
gs.info('Incident Number: ' + gr.getValue('number'));
}

Help others to find a correct solution by marking the appropriate response as the correct answer and helpful.

Siva Jyothi M
Mega Sage

Hi @Abhishek Kathe,

 

You can try the below code in BG script.

 

	var gr = new GlideRecord('incident');
	gr.addActiveQuery();
	gr.orderByDesc('sys_created_on');//you can replace with updtated as well
	gr.setLimit(10);
	gr.query();
	while(gr.next()){
	    gs.print(gr.number)
	}

 

Please mark this answer as correct and helpful if it solves your issue.

Regards,

Siva Jyothi M.