- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2022 01:48 PM
There are occasions where I'd like to grab the next number for a given table. However, calling NumberManager creates the next number. I just want to find out what the next number might be without incrementing in the database.
var nm = new NumberManager('square');
var number = nm.getNextObjNumberPadded();
gs.info(number); // SQ00123
I'd imagine the below may be the way to go or is there something I missed? Could there be a faster or better approach?
var nextNum;
var gr = new GlideRecord('square');
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
if (gr.next()) nextNum = gr.number;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2022 01:56 PM
Hello
Can you please try this below script
var nextNum ='';
var gr = new GlideRecord('square'); gr.orderByDesc('sys_created_on');
gr.setLimit(1);
if (gr.next())
{
nextNum = gr.number;
var spl =nextNum.split('SQ');
var num = spl[1];
var added = parseInt(num)+ 1;
var nextAddednum = 'SQ'+added.toString();
// this is your next number
}
This will not update your database with next number
Please accept the solution if you find it helpful
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2022 01:56 PM
Hello
Can you please try this below script
var nextNum ='';
var gr = new GlideRecord('square'); gr.orderByDesc('sys_created_on');
gr.setLimit(1);
if (gr.next())
{
nextNum = gr.number;
var spl =nextNum.split('SQ');
var num = spl[1];
var added = parseInt(num)+ 1;
var nextAddednum = 'SQ'+added.toString();
// this is your next number
}
This will not update your database with next number
Please accept the solution if you find it helpful
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2022 01:38 PM
Hey, thanks for improving my script! This was good!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2022 01:58 PM
Hi
Your approach is best. You are using the descending order with setLimit which will give you the quickest results as the GlideRecord will pick the latest record. No extra scroll through the records.
Regards,
Muhammad
Muhammad