Manage Learn to apply best practices and optimize your operations.

How to generate formatted sequence numbers with Formula language member Mohammed Misbahuddin provides step-by-step instructions and Formula language code that will generate five-digit sequence numbers, such as 00001 and 00002, in a Lotus Notes application.

When creating applications in Lotus Notes, it is often necessary to generate formatted sequence numbers. In this tip, I explain how to generate five-digit sequence numbers using Formula language.

The first unique number generated will be 00001, instead of 1, prefixed with four zeroes. The second generated number will be 00002, and so on. 

Just follow these steps:

  1. Create a field called "DocNumber" on the form.

  2. Make this field a "computed when composed" field.

  3. Create a view (it may be hidden), "(DocNumber)" based on the created form.

  4. This view should have "DocNumber" as the first sorted descending column.

  5. Write the Formula language code below in the value for the computed field called "DocNumber."
calc := @TextToNumber(@Word
("Notes" : "NoCache"; ""; "(DocNumber)"; 1))); " "; 1))
 + 1; @If(@IsNewDoc;@If(@IsError(calc); "0000"+"1"; 
@Text(calc);@Text(calc))); DocNumber)


Here's a shorter version of the code, which accomplishes the same thing:

calc := @TextToNumber(@Word
("Notes" : "NoCache"; ""; "(DocNumber)"; 1))); " "; 1))
+ 1; @If(@IsNewDoc;@If(@IsError(calc); "00001"; 
@right("00000" + @text(calc),5)); DocNumber)

—Deb L.


Here is a LISP programming language based way to do the same thing:


—Eric M.


Instead of checking the length of the sequence number, try this:

@Right("0000"+@Text(calc); 5)

—Gopinath P.


Here is simplified version to make the same computation into the field "DocNumber":

calc := @TextToNumber(@Max
(@DbColumn("Notes" : "NoCache";
 ""; "(DocNumber)"; 1)))+1; 
calc := @If(@IsError(calc); 1;calc); 
@Right("00000" +@Text(calc);5)

—Kari P.


How about using the following?

calc := @Word(@Implode(@Text
(@DbColumn("Notes" : "NoCache"; 
""; "(DocNumber)"; 1))); " "; 1)  + 1; 

pad := 10;

@Repeat( "0"; pad - @Length(calc) ) + calc

—Richard E.

Do you have comments on this tip? Let us know.

This tip was submitted to the tip library by member Mohammed Misbahuddin. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

More information on sequential numbering and Formula language:

Dig Deeper on Lotus Notes Domino Formula Language

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.



  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...