Tip

How to generate formatted sequence numbers with Formula language

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.
VIEW MEMBER FEEDACK TO THIS TIP
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.
More information on sequential numbering and Formula language:
Creating sequence numbers

Sequence numbering on a single server

Sequential numbering system for Lotus Notes applications

Formula language FAQs

Formula Language Learning Guide

Formula language tips and resources

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
(@Implode(@Text(@DbColumn
("Notes" : "NoCache"; ""; "(DocNumber)"; 1))); " "; 1))
 + 1; @If(@IsNewDoc;@If(@IsError(calc); "0000"+"1"; 
@If(@Length(@Text(calc))=1;"0000"+@Text
(calc);@Length(@Text(calc))=2;"000"+
@Text(calc);@Length(@Text(calc))=3;"00"+
@Text(calc);@Text(calc))); DocNumber)

MEMBER FEEDBACK TO THIS TIP

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

calc := @TextToNumber(@Word
(@Implode(@Text(@DbColumn
("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:

Count:=125;
NumberList:=0:1:2:3:4:5:6:7:8:9;
NumberBase:=10;
NL:=@Text(@Subset
(NumberList;NumberBase));
@Subset(NL*+NL*+NL;Count);

—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 SearchDomino.com 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.

This was first published in May 2007

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.