Sequential numbering + Document Lock

I am attempting to write script for an app that is in a clustered environment. I have decided not to write code to lock and unlock “Tracking” notes documents that keep track of current sequential numbers. Basically everytime a document is created a unique number is generated (by increments of 1). This is automated so that even 20 documents at a time is created automatically with button click.

My problem now is that duplicate numbering is happening. Because 2 or more workstations can access the “Tracking” number document which contains a number that the scripts increments.

There are no Notes errors, just continous new documents but with duplicate #s. My code checks for edits and saves that cannot be made. I am incrementing one each time. The script still generates duplicate numbers.

Anyone have ideas on how to continue with the next number without dups?

See sample script below:

If doc.Save(False, False) Then

Print "saved."

Else

Msgbox "NOT saved."

' Get next #

For i = 1 To 100

	Set doc = view.GetDocumentByKey( "NextNumber", True)

	Call GetNext

	NextNbrBPlusOne = NextNbrNNN + 1

	doc.NextNbr=NextNbrBPlusOne

	Call doc.Save(False, False)

	If doc.Save(False, False) Then

		Exit For

	Else

		Set doc = Nothing

	End If

Next

End If

Subject: Sequential numbering + Document Lock

Why are you looping 100 times, looking up a document and saving a documetn each time??? What exactly are you trying to achieve with this script?

Why not simply add a small script in the query save of the document, something like:

QuerySave Event:

dim doc as NotesDocument

Set doc = source.document

If doc.IsNewDoc then

doc.NextNbr = GetNextNumber (doc)

if doc.NextNbr(0) = “” Then

  MessageBox "Problem retreiving unique number. Please try again to save your document."

  Continue = false

  Exit sub

End if

Continue = true

End if

Assuming that the GetNextNumber function returns the next number for this document’s category, storing the new increment as it runs.

One thing is sure: you need to keep the lookup real fast and efficient, and trigegr it only as the user saves a new document the first time, so that the risk of getting a duplicate number is minimal. (since you dont want to lock it).

Would that help?

Nicolas Abesdris

Quintessence e-solutions Inc.