- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2025 06:11 AM
Hi Team,
Can anyone help me on this
how to get the latest created incident or sctask through scripts
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2025 11:44 AM
Hi @EswarS
What is the use case you have here? You can do it via list view and sort by created date.
Try this script:
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2025 12:04 PM
Hi,
Not sure what you want to do with the record you retrieve through the script, but here's something to show how to do.
var latestIncGR = new GlideRecord('incident');
latestIncGR.orderByDesc('sys_created_on'); // sort by created
latestIncGR.setLimit(1); //only retrieve one record
latestIncGR.query();
if (latestIncGR.next()){
gs.info('Number: ' + latestIncGR.getValue('number'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2025 12:26 PM
Hi @EswarS
You can execute this script in background script or any other script execution environment in ServiceNow. I recently created three incidents on my PDI, and use this script in background script to test. Kindly find attached.
Regards,
Mimi Edet
LinkedIn: https://www.linkedin.com/in/edet-promise/
=========================================================
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2025 11:44 AM
Hi @EswarS
What is the use case you have here? You can do it via list view and sort by created date.
Try this script:
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2025 12:04 PM
Hi,
Not sure what you want to do with the record you retrieve through the script, but here's something to show how to do.
var latestIncGR = new GlideRecord('incident');
latestIncGR.orderByDesc('sys_created_on'); // sort by created
latestIncGR.setLimit(1); //only retrieve one record
latestIncGR.query();
if (latestIncGR.next()){
gs.info('Number: ' + latestIncGR.getValue('number'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2025 05:19 PM
Thank U OlaN
ur script worked fine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2025 12:26 PM
Hi @EswarS
You can execute this script in background script or any other script execution environment in ServiceNow. I recently created three incidents on my PDI, and use this script in background script to test. Kindly find attached.
Regards,
Mimi Edet
LinkedIn: https://www.linkedin.com/in/edet-promise/
=========================================================
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."