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.)
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
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
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()).
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.
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.
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.