- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago - last edited 7 hours ago
Requirement- I have a table 'test' and I would like to create 2 auto generate number fields. For ex: 1st-> test00001 (default)
2nd- > currentyear/01, currentyear/02 and so on should be auto generated based on certain conditions.
Can I have 2 number maintenance records for the same table as it doesn't have field name or any other approach?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
For 1st field (e.g u_custom_num_1) , you can enable auto numbering . (refer: Auto-Numbering Records: How it works and how to remove it)
.
For 2nd field - If you do not need the number to be generated prior to inserting the record, in that case you can ,you can use before insert Business Rule .
Sample code - //not tested.
(function executeRule(current, previous /*null when async*/) { if (current.category == 'hardware') // Add your condition if any
{ current.u_custom_num_2 = "currentyear/" + current.number.toString().slice(-2) ; //with currentyear you can append 1st field's last 2 digit. } })(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi @Purvi Kotadiya
No — you cannot have 2 “Number Maintenance / auto-number” records for the same table to generate 2 different auto-numbers. ServiceNow table auto-numbering supports only ONE numbering scheme per table (it uses a single number_ref).
Solution:- If you need a 2nd auto-generated value (like YYYY/01, YYYY/02…), create it as a separate String field and populate it via a Business Rule / script (or use a separate counter logic per year).
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Hello @namanajain, thanks for the response. I was thinking of BR, but then will it be con currency safe?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Reference :- How to access getNextObjNumberPadded() in a client... - ServiceNow Community
Don't directy just use (number+1) it will not work on multiple submissions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
@Purvi Kotadiya If u find the solution. Please Accept it as solution.
Thanks
