Generating unique numbers in Domino using LotusScript

This IBM LotusScript tip illustrates the use of Profile Document to generate unique numbers.

View member feedback to this tip.

This tip illustrates the use of Profile Document to generate unique numbers.

Most Notes workflows are based on Defects. So here I present a real-world example for generating unique Defect Tracking Number. (With this tip you can get rid of the issue of 64K limit as in DBLookUp.)

The idea behind this is to capture the latest Defect Tracking Number in the public profile document. This should be done using the two functions below. Put these two functions in a script library named slTracker and use it on the Defect form. Call setLatestDefectNumber() when saving the Defect Form. Call getLatestDefectNumber() in QueryOpen event to assign it to DefectNumber field.

Caution: Make sure the Profile Document is updated only for new Defect Documents.

Public Function getLatestDefectNumber() As String
 On Error Goto errorHandler
 getLatestDefectNumber = ""
 
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim docProfile As NotesDocument
 
 Dim lastDefectNumber As String
 Dim newDefectNumber As String
 Dim temp As Variant
 
 Set db = session.CurrentDatabase
 Set docProfile = db.GetProfileDocument("DefectNumber")
 
 If Not docProfile Is Nothing Then
  If docProfile.HasItem("LastDefectNumber") Then
   lastDefectNumber = Cstr(docProfile.GetItemValue("LastDefectNumber")(0))
   Temp = Clng(lastDefectNumber) + 1
   newDefectNumber = Cstr(Temp)
  End If
 End If
 
 getLatestDefectNumber = newDefectNumber
 Exit Function
errorHandler:
 getLatestDefectNumber = ""
End Function

Public Function setLatestDefectNumber(strDefectNumber As String) As Boolean
 On Error Goto errorHandler
 setLatestDefectNumber = False
 
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim docProfile As NotesDocument
 
 Dim lastDefectNumber As String
 Dim newDefectNumber As String
 Dim temp As Variant
 
 Set db = session.CurrentDatabase
 Set docProfile = db.GetProfileDocument("DefectNumber")
 
 If Not docProfile Is Nothing Then
  If docProfile.HasItem("LastDefectNumber") Then
   Call docProfile.ReplaceItemValue("LastDefectNumber",strDefectNumber)
   Call docProfile.Save(True,False)
  End If
 End If
 
 setLatestDefectNumber = True
 Exit Function
errorHandler:
 setLatestDefectNumber = False
End Function

MEMBER FEEDBACK TO THIS TIP

The worst place to store the highest number (incremental numbering) is in a profile document. That's because profile documents are cached locally on the Notes client. So if someone opens the application, and leaves it open, and in the meantime other people create new documents, it's possible the profile document the first user has is its cache, is out of date, and the sequence gets wrong.

There are better places to store this type of info. One is in normal notesdocuments (access by view, or put one document in a folder). Another is to use the lookup to a view in LotusScript. If you are writing script, the 64K limit won't affect you (getfirstdocument()).

—Tom B.

******************************************

This tip can produce conflicts. Access by either view or folder is a better solution, but it's possible to generate document conflicts. With "lock" document, you have no problem.

—Pablo D.

******************************************

How can you manage a unique number when you have the same application running on multiple servers all connected via a switch? That's where it gets tricky and the method described fails.

—Sanatan P.

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

This tip was submitted to the SearchDomino.com tip exchange by member Sunilkumar Vishwakarma. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.

This was first published in September 2005

Dig deeper on LotusScript

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close