Lotus Notes FAQ Visit Our Sponsor!

How do you generate unique document numbers?


Because of the nature of Notes database replication, there is no way to generate unique document numbers. What is normally done to give each document a unique key is to concatenate the users name or initials with the date, and the time of document creation. An example can be found in Lotus Notes Call Tracking Database example. Another example is below:

TimeNow := @Now;
YearString := @Right(@Text(@Year(TimeNow)); 2);
MonthString := @Select(@Month(TimeNow); "01"; "02"; "03"; "04"; "05"; "06"; "07"; "08"; "09"; "10"; "11"; "12");
DayNumber := @Day(TimeNow);
DayString := @Select(DayNumber; "01"; "02"; "03"; "04"; "05"; "06"; "07"; "08"; "09";  @Text(DayNumber));
HourNumber := @Hour(TimeNow);
HourString := @If(HourNumber = 0; "00"; @Select(HourNumber; "01"; "02"; "03"; "04"; "05"; "06"; "07"; "08"; "09"; @Text(HourNumber)));
MinuteNumber := @Minute(TimeNow);
MinuteString := @If(MinuteNumber = 0; "00"; @Select(MinuteNumber; "01"; "02"; "03"; "04"; "05"; "06"; "07"; "08"; "09"; @Text(MinuteNumber)));
SecondNumber := @Second(TimeNow);
SecondString := @If(SecondNumber = 0; "00"; @Select(SecondNumber; "01"; "02"; "03"; "04"; "05"; "06"; "07"; "08"; "09"; @Text(SecondNumber)));
UniqueID := YearString + MonthString + DayString + HourString + MinuteString + SecondString + @Left(@Name([CN];@UserName); 1) + @MiddleBack(@Name([CN];@UserName); " "; 1)

Note that if this code is called twice, it doesn't take into account that there may be duplicate values. To prevent this case, you have to have a hidden view with all the unique numbers sorted. Then, do a @DbLookup to see if the value is already used.

For Notes 4 and above, you can use the @Unique function to get Notes' unique document ID.


Applies to Notes Versions: 3, 4, 4.5, 4.6, 5
Last Modified: September 19, 1999