I have a situation where I need to number automatically the documents on Notes and also on the WEB.
For the Notes Client I use script that lock a file which contains the current number
Sub Initialize
file% = Freefile
Open "c:\\seqnum.bin" For Binary Access Read Write Lock Read As file%
' You can also use Open "\\NotesServer\SharedDirectory\seqnum.bin"
' if your client and server are Win95 or NT based. Open can take
' a UNC path
Get #file%, 1, SeqNum%
SeqNum% = SeqNum% + 1
Put #file%, 1, SeqNum%
Close file%
End Sub
This solution generate real time sequential number but it isn't very good because all users needs to have write right on the file system server (on a folder from the server) :'(
For the Web I use a simple method:
sub initialize
Dim session As New notessession
Dim db As notesdatabase
Dim doc As notesdocument
Dim backdoc As notesdocument
Dim view As notesview
Set doc = session.documentcontext
Set db=session.currentdatabase
Set view=db.getview("RequestID")
Set backdoc=view.getfirstdocument
If Not backdoc Is Nothing Then
LastID = backdoc.requestID(0)
Else
LastID = 0
End If
If LastID <> "" Then
NextID = LastID + 1
Else
NextID = 1
End If
FormattedID = Trim(Str(NextID))
' pad the ID to be 6 characters, with leading zeros
For x% = 1 To (6 - Len(FormattedID))
FormattedID = "0" + FormattedID
Next
doc.replaceItemValue("Requestid", FormattedID);
End sub
but when 2 or more users try to create docs inthe same method I will get duplicate numbers ....
Each of these records records needs to be assigned a unique, seven-digit number. The number needs to be assigned when the record is intially saved and never changed after that. Records normally stay on the database only 45-60 days, so a rolling number should not cause problems.
The system currently uses and algorithm based on the current date and time to calculate a value, but we are getting duplicates because Notes time can only go to seconds. Two records added in the same functional area in a one second window are assigned the same number. Even if milliseconds were available it would not help since that would return a value greater than 7 digits and we are limited to that size based on external systems fed from our application.
Some options ... The database includes user profile documents and we suggested adding a counter to that record, but it is concerned about sharing names & passwords. The system needs to work even if two people use the same sign-on.
Is there any way to access an external file (ODBC or sequential) with calls from Notes and guarantee unique sequential numbers? I do not have Notes Pump and prefer not to use Lotus Script connections to ODBC because of response concerns. Any directions or suggestions would be appreciated.