Document Locking and Web Agents

Hoping someone can help with this.

I’m writing a little web app that needs a sequentially generated tracking number.

On the WebQueryOpen event, the form calls a background agent that, amoung other things, gets the next sequential number.

The function that gets the next number is simple. It gets a profile document, gets the current number, adds 1, saves the new number back to the profile document, then passes it to the context document.

So I wanted to make use of document locking to ensure that I don’t end up with duplicate numbers or save conflicts but, given the way document locking works, I can’t find a way to implement this.

Since…

(a) - I don’t want to give all web users access to the profile document (and other thinks), the background agent is not set to “run as web user”.

…and…

(b) - Document locking uses the effective user name when applying the lock.

…the method will return ‘True’ because the user name will always be in the ‘LockHolders’ property.

So my question is, can anyone think of a way to get this to work or suggest an alternative?

Thanks in advance

Ernest

Subject: Document Locking and Web Agents - FOUND SOLUTION

Please disregard parent post - I figured it out…

Subject: RE: Document Locking and Web Agents - FOUND SOLUTION

Just out of curiousity, what did you end up doing?

Subject: Better late than never…

Here’s the function I implemented (along with enabling Document Locking in the database properties).

Function getNextTicketNumber(fatsdb As NotesDatabase) As String

Dim view As NotesView

Set view = db.GetView("lookup2")

Dim lookupDoc As NotesDocument

Set lookupDoc = view.GetDocumentByKey("TheNumber*NextNumber")

Do While (lookupDoc.LockHolders(0) <> "")

	

	Sleep(0.1)

	Set lookupDoc = view.GetDocumentByKey("TheNumber*NextNumber")

	

Loop

nextNumber = lookupDoc.field_1(0)

lookupdoc.field_1 = Clng(nextNumber+1)

Call lookupDoc.Save(True,False, True)

Call lookupDoc.UnLock()



getNextTicketNumber = "F" &nextNumber

End Function

Essentially it just keeps checking the LockHolders property until it is null…