Serial Number Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 08:49 AM
Hi All,
I want to create a serial number field in a table (starting with 1 and counting).
Is there a type that matches this requirement?
Thanks in advance 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 11:11 AM
@Snow Tomcal Please refer to the documentation https://docs.servicenow.com/en-US/bundle/vancouver-platform-administration/page/administer/field-adm... to add auto numbering to your table.
If you do not wish to you OOTB auto numbering and would like to implement your custom logic, then you can choose to create an onBefore Insert business rule. Inside the script you can write the following script to implement auto numbering.
var glideTable = new GlideAggregate('<Your table name>'); //Add your table name here
glideTable.addAggregate('MAX','<your number field>');
glideTable.setGroup(false);
glideTable.setOrder(false);
glideTable.query();
if(glideTable.next()){
var newNum = glideTable.getAggregate('MAX','<your number field>');
current.<your number field>=parseInt(newNum)+1; //set the value of your number field here
}
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 12:40 PM
Hi @Snow Tomcal,
If you want to have a prefix use Autonumbering as @Sandeep Rajput advised.
Otherwise the type you want to use is integer.
You can fill it with a onBefore Business Rule without the need of using GlideAggregate like this:
var gr= new GlideRecord('<<Table name>>');
gr.orderByDesc('<<Number Field>>');
gr.setLimit(1);
gr.query();
gr.next()
var newNum = gr.getValue('<<Number field>>');
current.<<Number field>> = ++newNum;
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.