Manage Learn to apply best practices and optimize your operations.

Unique Sequential Numbering On The Web..

There have been many situations where Notes documents need to be uniquely
numbered. Usually, the NoteID would be an easy choice. But the document NoteID
is not sequential, and it also contains alphabets. If you wanted sequential
numbering, an option would be to write some code using @Dblookup,
Querysave/Queryclose check the last number that was allocated and then allocate
the next number to the next document. This would be a viable option if the
number is to be allocated after the document is saved.

The premise of the problem is, a unique sequential number needs to be allocated
to a newly created document. If the document is then cancelled (Not saved), the
number must be made available to the next document that is created. A good
application of this functionality would be in a Bug Tracking database. Each bug
needs to be sequentially numbered, so that at any time, the number of bugs in
the application can be known, and there should be no duplicate numbers for the
bugs.

I have seen many implementations of this on the Notes Client, using the
Queryopen/QueryClose events, and some script, but what about a similar
functionality on the web? Note that on the web, Queryclose cannot be tracked.
The code uses profile documents to obtain this functionality. When the first
document is created in the database, it is allocated a number of "1". An entry
is made into the Profile document, "1; &LTtime when the document was created>".
If the document is saved, the entry is deleted from the Profile document. If
the document is not saved, the entry remains. The next document that is created
checks the profile document. If the time stamp on the unique number is more
than 2 hours ago, the number is used by the new document, and the time stamp is
updated to the current time. If the time stamp has not expired, the document
checks the number on the last document, and adds 1 to it, and uses it.

Design elements required:
1. Create a form, call it "frmDBProfileDoc". Create one field in it, called
ID_Number, Editable Text. This will be used as the Database Profile document.

2. Create the form, whose documents need to be sequentially numbered. Call it
"Seqdoc". Call the field that contains the number as "ID" - Computed Text,
value of "ID".
In the WebQueryOpen event, enter the name of the agent - "GenerateID"
In the WebQuerySave event, enter the name of the agent - "SaveDoc"

3. Create a view, - "ById", which contains the documents created with the
"Seqdoc" form, and the first sorted column contains the ID field.

4. Create the GenerateID agent - Manually from Agent list, run once(@Commands
may be used)
The code in the agent runs thus:

Sub Initialize
Dim session As New Notessession
Dim database As Notesdatabase
Dim Web_Document As Notesdocument
Dim Profile_Document As Notesdocument
Dim First_Document As Notesdocument
Dim ID_View As Notesview
Dim No_Of_Entries As Integer
Dim ID_Item As Notesitem
Dim Temp_Array(0 To 1) As String
No_Of_Entries=0

Set Web_Document = session.DocumentContext
If Web_Document.IsNewNote Then
Set database = session.Currentdatabase
Set Profile_Document =database.GetProfiledocument("frmDBProfiledoc")
Set ID_View = database.GetView("byid")
Set First_Document = ID_View.Getfirstdocument
Set ID_Item = Profile_Document.GetFirstItem("ID_Number")

'Get the number of entries in the Profile Document field ID_Number
Forall i In Profile_Document.ID_Number
No_Of_Entries=No_Of_Entries+1
End Forall

If Profile_Document.ID_Number(0) = "" Then
If First_Document Is Nothing Then
Unique_ID$="000001"
Else
Unique_ID$=Right$("000000" + Cstr(Cint(First_Document.ID(0)) + 1), 6)
End If
Web_Document.ID = Unique_ID$
Profile_Document.ID_Number = Return_Array(Unique_ID$,
Cstr(Web_Document.Created))
Call Profile_Document.Save(True, True)
Else
Dim Old_Date As New Notesdatetime(Profile_Document.ID_Number(1))
Dim New_Date As New Notesdatetime(Now)
If (New_Date.Timedifference(Old_Date) < 2*60*60) Then
If Not(First_Document Is Nothing) Then
'--------------------------------------------------------------
'Get the highest profile value
Profile_Last_Value% = Bubble_Sort(Profile_Document, No_Of_Entries)
'--------------------------------------------------------------
Document_Last_Value% = Cint(First_Document.ID(0))
If (Profile_Last_Value%>Document_Last_Value%) Then
Unique_ID$= Right$("000000" + Cstr(Profile_Last_Value% + 1), 6)
Else
Unique_ID$= Right$("000000" + Cstr(Document_Last_Value% + 1), 6)
End If
Else
Unique_ID$ = "000001"
End If
Web_Document.ID=Unique_ID$
Temp_Array(0) = Unique_ID$
Temp_Array(1) = Cstr(Web_Document.Created)
Call ID_Item.Appendtotextlist(Temp_Array)
Call Profile_Document.Save(True, True)
Else
Profile_First_Value% = Cint(Profile_Document.ID_Number(0))
Unique_ID$= Right$("000000" + Cstr(Profile_First_Value%), 6)
Web_Document.ID = Unique_ID$
Temp_Array(0) = Unique_ID$
Temp_Array(1) = Cstr(Web_Document.Created)
Call Pop(Profile_Document, No_Of_Entries)
Call ID_Item.Appendtotextlist(Temp_Array)
Call Profile_Document.Save(True, True)
End If
End If
End If&LTWHATL

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

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

SearchDataCenter

SearchContentManagement

Close