How to create auto number for the field in the custom table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello Everyone I'm currently working on my project called My College ,i am trying to auto generate a number for an field which is string i am not able to do that can anyone guide me .
I'm working on an Application called as My College where all the People related to college can use this application to fulfill their request if anyone have ideas which can be included in this project please share them, those will be most useful to me and project
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @mohammadtaneem ,
You can generate roll numbers by following these steps:
Navigate to System Definition → Number Maintenance.
Click New and choose the table where you want the roll number (e.g., x_custom_roll_table).
Enter:
Prefix → e.g., ROLL
Number → starting value, e.g., 0001
Increment → usually 1
Save it. Now, whenever a new record is created, ServiceNow will auto-generate numbers like ROLL0001, ROLL0002, etc.
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @mohammadtaneem ,
You have to navigate to All > System Definition > Number Maintenance
and Create new record there give suffix, Number and Number of digit and check whether it's create number on the table.
Thanks,
Rithika.ch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
See the steps below --- you can do it.
Part 1: Auto-Generating a Unique Number (The ServiceNow Way)
You're right that you can't just set a string field to "auto-increment" like a number. However, ServiceNow has a powerful, built-in system specifically for this, called Number Maintenance. This is the best-practice method and avoids complex, unnecessary scripting.
The process involves two main steps:
Create a Number Definition: You define how your number should look (e.g., COL0001, STU0002, etc.).
Apply the Definition to Your Table: You tell your field to use this new definition for its default value.
Here is a step-by-step guide:
Step 1: Create the Number Record
In the ServiceNow filter navigator (the search bar on the left), type sys_number.list and press Enter. This will take you to the list of all number definitions in the system.
Click the New button to create a new record.
Fill out the form:
Table: Start typing the name of your custom table (e.g., u_my_college_request) and select it.
Prefix: This is the static text that will appear at the beginning of every number. For example, you could use COL for "College".
Number of digits: Enter the number of digits for the numeric part. 7 is a common choice, which allows for millions of records (e.g., COL0000001).
Starting number (optional): You can leave this as the default 1,000 or set it to 1.
Make sure the Active checkbox is checked.
Submit the form.
Step 2: Apply it to Your Field
Now you need to tell your string field on the "My College" table to use this new number format.
Navigate to your custom table's form.
Right-click the header of the form and go to Configure > Form Layout or Configure > Form Design.
Find your string field (e.g., "Request Number") and click the gear icon next to it to see its properties.
In the Default value tab or field, enter the following JavaScript snippet:
javascript:getNextObjNumberPadded();
Save it by clicking save.
That's it! Now, every time a new record is created in your "My College" table, ServiceNow will automatically generate the next available number (e.g., COL0001001, COL0001002, etc.) and place it in that string field before the record is saved.
Disclaimer: Please note that the information and advice provided above are based on my personal experience and are not official solutions or professional advice from DXC Technology. No patent code or solution from DXC Technology has been shared
If this response helped resolve your problem, please kindly mark it as the Best Answer 🌠. If it gave you some useful insight, a Helpful ⛑ mark would be wonderful too! Your feedback encourages me to contribute more to our amazing community.