how to get latest 10 records which are created from incident table

lavanya lavanya
Kilo Explorer

how to get latest records  which are created from  incident table

1 ACCEPTED SOLUTION

Harihara Sudha1
Kilo Expert

Hi Lavanya,

Can you explain more about your question? Whether you neded to get the records in flow or  business rule?

Thank you

Harihara Sudhan M S

View solution in original post

3 REPLIES 3

Harihara Sudha1
Kilo Expert

Hi Lavanya,

Can you explain more about your question? Whether you neded to get the records in flow or  business rule?

Thank you

Harihara Sudhan M S

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

something like this

var gr = new GlideRecord("incident");
gr.orderByDesc('sys_created_on');
gr.setLimit(10);
gr.query();
while(gr.next()) {
	gs.info(gr.number);
}

Regards
Ankur

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

Gaurav Shirsat
Mega Sage

Hello

If you are supposed to be doing this in server side script: kindly follow

 

var grTab= new GlideRecord("<table name>");//here it will be incident

grTab.orderByDesc("sys_created_on");

grTab.addActiveQuery();//if you need 10 records which are in new/on hold/in progress/resolved state.

//if you need random first 10 records then remove above line of script

grTab.setLimit(10);//you need 10 so we have added 10 here, change accordingly.

grTab.query();

while(grTab.next())

{

gs.addInfoMessage(grTab.Number);//you will get the numbers displayed

}

kindly refer Docs for additional info

Mark my Response as Correct or Helpful, if you find it Appropriate.
Gaurav Shirsat : ServiceNow Community MVP 2022
https://www.linkedin.com/in/gauravshirsat/