- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2020 06:17 AM
Hello,
I have a script include that looks up records in my 'hour tracker' table. It finds records that match the name of the employee parameter. Now I just need to find the most recently inserted record so that I can pull field values from it. How can this be done?
This is what I have so far:
get_lastContract: function() {
var grEnd = new GlideRecord('x_utsll_time_manag_hour_tracker');
grEnd.addQuery('name_of_employee', this.getParameter('sysparm_nameEmployee'));
grEnd.query();
if (grEnd.next()){
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2020 06:32 AM
Just checked on my PDI, because it was a theoretical answer. Though checked if it also works for scoped: works fine.
(function() {
var gr = new GlideRecord('x_utsll_time_manag_hour_tracker');
gr.addQuery('name_of_employee', this.getParameter('sysparm_nameEmployee'));
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr._query();
if(gr._next()) {
gs.info(gr.getDisplayValue() + ', created: ' + gr.getValue('sys_created_on'));
}
})();
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2020 06:22 AM
Hi JJG,
This code would give me the most recent created incident. So just adjust it to your table.
(function() {
var gr = new GlideRecord('incident');
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr._query();
if(gr._next()) {
gs.info(gr.getDisplayValue() + ', created: ' + gr.getValue('sys_created_on'));
}
})();
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2020 06:32 AM
Just checked on my PDI, because it was a theoretical answer. Though checked if it also works for scoped: works fine.
(function() {
var gr = new GlideRecord('x_utsll_time_manag_hour_tracker');
gr.addQuery('name_of_employee', this.getParameter('sysparm_nameEmployee'));
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr._query();
if(gr._next()) {
gs.info(gr.getDisplayValue() + ', created: ' + gr.getValue('sys_created_on'));
}
})();
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field