Home > Domino Tips > Developer > Other > Sequence numbering on a single server
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

OTHER

Sequence numbering on a single server


Oliver Blion
01.27.2004
Rating: -2.71- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.

Code

'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
 uiws.CurrentDocument.Document.
Counter = doc.nextSeqNum

MEMBER FEEDBACK TO THIS TIP

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.


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Other
Create a dynamic user-driven navigator for a Notes/Domino application
How to apply XSL style sheets to XML views
Comparing replicas on clustered Lotus Domino servers
Creating a Lotus Notes view column categorized by month
Using the XMLHTTP object for integration with Domino or any RDBMS back end
Hiding field properties/data from DocProperties box
Export a view to Excel without coding
Prevent document deletion if there are response documents
Switching between test IDs quickly
AddParameter to a NotesXSLTransFormer

Lotus Notes Domino Agents
How the Agent Profiler tool improves Notes/Domino performance
Run or restart Notes/Domino agents via text messages
Calculating results for a column in a Lotus Notes view
Approve Lotus Notes documents using a BlackBerry mobile device
LotusScript agent indexes Lotus Notes/Domino databases
Top 10 Lotus Notes/Domino coding and development tips of 2008
Open documents in Lotus Notes from the Web without a UNID
Fix and update Lotus Notes documents with limited access
Verify scheduled agent status with Domino Extensible Language (DXL)
Top 10 Lotus Notes Domino programming and development tips of 2007

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts