Background:
We have a project management database. When a project si created a number is assigned based off a profile document. When the number is taken the profile document is incremented to reflect that.
This all works fine, however sometimes - and I cant figure out why, a duplicate number will get created. Once the duplicatew number is created all entries after that are stuck ont he same number.
To fix this we made a “fix duplicate agent”.
You select the item that needs fixing in the view and runt he agent.
Here is the code:
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim currentDoc As notesDocument
Set db = session.CurrentDatabase
Set currentDoc=session.DocumentContext
Set doc = db.GetProfileDocument("Counter")
Call currentDoc.replaceItemValue( "count", Cstr( doc.getItemValue( "counter")( 0)))
Call currentDoc.Save(True,True)
Call doc.replaceItemValue( "count", doc.getItemValue( "counter")( 0) + 1)
Call doc.Save(True,True)
Exit Sub
errorHandler:
Print "Error #" & Format$(Err) & " at line " & Format$(Erl) & ": " & Error$, 0, "Error"
End Sub
OK the script runs fine and updates the document with the next available project number. This is great.
However when you go to the next document int he view that needs correction and run the correction tool, it does the same thing and assigns the number it just assigned!
So If you have more than one duplicated document (which is usually the case) the fixer will only work on the first one you choose to fix. It doesnt run on the others.
Is my logic wrong or is this code wrong?
Is it doing what I tell it to do, or am I telling it the wrong thing.
Any insignt is appreeciated.
Feels like christmas lights, one goes out then they all go out.