Pring Lat 5 records of current logged in user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2024 02:34 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2024 01:30 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2024 01:39 AM
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.