Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

how to create 2 auto generate sequence number fields in single table?

Purvi Kotadiya
Mega Expert

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?

 

 

1 ACCEPTED SOLUTION

Tanushree Maiti
Kilo Patron

Hi @Purvi Kotadiya 

 

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);

  

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

View solution in original post

6 REPLIES 6

Tanushree Maiti
Kilo Patron

Hi @Purvi Kotadiya 

 

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);

  

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Thanks @Tanushree Maiti , This solution works 😀