Manage Learn to apply best practices and optimize your operations.

Sequence numbering on a single server

How to create sequence numbers that don't duplicate, even when run off a server or local client.

View member feedback to this tip.

I've looked at all the sequence number generators and they are either specific to a version or have many design elements. To avoid any duplications, I use the session.saveddata class property. When called and used from an agent, it will produce sequence numbers that never duplicate, even if run off a server or local client.

How to use this class property: Create a hidden manually run agent and place this script in the initialize.

'create next sequence number. 
Stored in agent.
 Dim session As New NotesSession, 
doc As NotesDocument
 Set doc = session.SavedData
 If doc.HasItem("nextSeqNum") Then
  doc.nextSeqNum = 
doc.nextSeqNum(0) + 1
 Else 'no number found. use a 
default sequence number to start.
  doc.nextSeqNum = 1 End If
 Call doc.Save( True, False)
 'transfer result to current document. 
Up to you which method you use. 
Depends on how and where agent 
executed. e.g., post open event
 Dim uiws As New NotesUIWorkspace
Counter = doc.nextSeqNum


This code should be used very carefully: "SaveData" document is deleted and recreated each time the appropriated agent is resaved. Therefore, the counter would be reinitiated each time you update the database's design.

-- Aleksei S.


The code here is fine for coming up with "A Number" but runs the risk of generating multiple duplicate numbers if more then one user goes for a number at near the same time.

The big problem is that writing and reading takes time and there are no checks available to tell you if someone is reading/writing or what they are doing. The only workaround I've ever found for avoiding duplicate numbering in multi-user situations is a technique I call "Who's got the Mike." The idea is highly simplistic. You create a document I call a control document.

It exists alone and has an author field. This document represents the "Mike." When no one is generating a unique number the author field contains an asterisk (*) which means anyone can have it. When a user needs a unique number the code "tries" to place that users name in the author field of the control document and save it. If they succeed in saving the control document then they had editor access to the control document and they, "Have the Mike" and can make a new number.

Anyone else trying to generate a number now will be blocked because they can't save their name in the author field of the control document. They have to wait. Once the system has generated the new number and recorded that fact for future number generation, the control document is populated with an asterisk and saved -- thus allowing anyone else to grab it and create a unique number.

This approach is as close as I've ever come to assuring unique numbers in multi-user applications where more then one user could attempt to get a unique number at the same time. Only one person can own the control document at any time.

—John G.

Do you have comments of your own? Let us know.

Dig Deeper on Lotus Notes Domino Agents

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 ...