How to number documents in order - 1,2,3,4, etc. vs. random numbers?

How do you number your documents in order - 1, 2, 3, 4, etc. instead of a random number?

Subject: How to number documents in order - 1,2,3,4, etc. vs. random numbers?

search on “sequential numbering” for lots of hits.

regards,

raphael

Subject: How to number documents in order - 1,2,3,4, etc. vs. random numbers?

To do this, create a view with the first column based on a field called say sequence. Sort it. Then in the QuerySave event of the form, get the last value in this view and increment it by one. Assign this value to the sequence field.

The Drawback to this method is that if two people create a document at the same time, they get the same sequence number.

A work-around is to NOT create the sequence number when the document is saved, but to use a scheduled agent to set all of the sequence numbers in a view sorted by date and time. This agent would run and loop through the view, adding the sequence numbers to documents which did not have them.

The drawback here is that the sequence number will not be availabe immediately when the document is saved.

You could also keep a “pool” of sequence numbers in a document. When composing a document, the next number is obtained and removed from the pool document. This gives you the number before you save the document. HOWEVER, this has a large drawback in that if you compose a document, and someone else composes a document (giving you #5 and them #6 for instance) and then you do not save your document, there will be the obvious gap in numbers.

We use the first method, though a combination of methods one and two could also be useful in many situations. Note that this method uses Client-only techniques for getting a handle to the document, but can be easily adapted to work from a browser via an agent called in WQS.

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim s As New NotesSession

Dim wk As New NotesUIWorkspace

Dim db As NotesDatabase

Dim view As NotesView

Dim cdoc As notesdocument

Dim uidoc As notesuidocument

Dim idoc As NotesDocument

Dim lincnum As Integer



Set db = s.CurrentDatabase

Set view = db.GetView("(All Incidents)")

Set idoc = view.GetLastDocument

Set uidoc = wk.CurrentDocument

Set cdoc = uidoc.Document



'This view should be sorted on numIncNumber to allow you to get the highest number by obtaining the last document in the view.				

Set clview=db.GetView("All Incidents")

Call clview.refresh()



If (cdoc.numIncNumber(0)="") Then

	Set cldoc=clview.GetLastDocument

	If (cldoc Is Nothing) Then

		'This is the first document				

		cdoc.numIncNumber="0000001"					

	Else			

		tempnum = Csng(cldoc.numIncNumber(0)) + 1

		zeros=7-Len(Cstr(tempNum)) ' However many zeroes you need

		tempStr=Cstr(tempnum)

		For i=1 To zeros

			tempstr= "0"+tempstr

		Next

		cdoc.numincNumber=tempstr

	End If

End If

End Sub

Subject: RE: How to number documents in order - 1,2,3,4, etc. vs. random numbers?

Thank you, Joel for your excellent help.