The CreatorCon Call for Content is officially open! Get started here.

Pring Lat 5 records of current logged in user

Chiranjeevi K
Tera Expert

I am sure the below script will print the last 5 records created on the system but am looking to print last 5 records assigned to the logged in user , could anyone please help me with the change on the below script.

var gr = new GlideRecord('incident);
gr.orderByDesc('sys_created_on');
gr.SetLimit(5);
gr.query();
while(gr.next(){
gs.print('incident number: '+gr.number);
}

11 REPLIES 11

Rajdeep Ganguly
Mega Guru

Sure, you can modify the script to filter the incidents assigned to the current logged-in user. Here's how you can do it: javascript var gr = new GlideRecord('incident'); gr.addQuery('assigned_to', gs.getUserID()); // filter incidents assigned to the current user gr.orderByDesc('sys_created_on'); gr.setLimit(5); gr.query(); while(gr.next()) { gs.print('incident number: ' + gr.number); } Here's the summary: - Create a new GlideRecord object for the 'incident' table. - Add a query to filter incidents assigned to the current logged-in user using gs.getUserID(). - Order the results by 'sys_created_on' in descending order. - Limit the results to the last 5 records. - Query the database. - Loop through the results and print the incident number for each record.

sumanta pal
Kilo Guru

Sure, you can modify the script to filter the incidents assigned to the current user. Here's how you can do it: javascript var gr = new GlideRecord('incident'); gr.addQuery('assigned_to', gs.getUserID()); // filter incidents assigned to current user gr.orderByDesc('sys_created_on'); gr.setLimit(5); gr.query(); while(gr.next()) { gs.print('Incident number: ' + gr.number); } Here's the summary: - Create a new GlideRecord object for the 'incident' table. - Add a query to filter incidents assigned to the current user using gs.getUserID(). - Order the results by 'sys_created_on' in descending order. - Limit the results to the last 5 records. - Query the database. - Loop through the results and print the incident number.