I’ve come across a problem recently where a response document is referencing itself or another response as the parent.A simple copy/paste onto the parent document isn’t fixing the problem.
I’ve put together some code to reset the $Ref field to correct the problem. (As yet, I don’t know how, when or why the problem is happening.)
In my code, I have a (parent) Task Log and a (child) Worksheet. The code works by:
-
pulling the LogNumber field from the Worksheet,
-
going to a view showing a Task Logs by Log Number,
-
finding the parent Task Log,
-
getting the parent Task Log UNID,
-
setting the child Worksheet’s $REF field to the parent’s UNID,
-
removing the $Conflict field from the child Worksheet
-
saving the child Worksheet
Options:
-
instead of pulling the LogNumber field from the Worksheet, use an InputBox to get the data (also remove the loop and process one document at a time)
-
omit removing the $Conflict field
-
do something fancier if the parent Task Log isn’t found
Here’s the code. If you do any modifications, it would be great to post them here as well.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim coll As NotesDocumentCollection
Dim pdoc As NotesDocument
Dim rdoc As NotesDocument
Dim plog As Double
Set db = session.CurrentDatabase
Set view = db.GetView("Log Number Reset")
Set coll = db.UnprocessedDocuments
Set rdoc = coll.GetFirstDocument
Do Until rdoc Is Nothing
plog = rdoc.LogNumber(0)
Set pdoc = view.GetDocumentbyKey(Cdbl(plog))
If pdoc Is Nothing Then
Msgbox "Log #" & Cstr(plog) & " not found."
Goto NextDoc
End If
Call rdoc.MakeResponse(pdoc)
Call rdoc.RemoveItem("$Conflict")
Call rdoc.Save(True, True)
NextDoc:
Set rdoc = coll.GetNextDocument(rdoc)
plog = 0
Loop
Msgbox "Worksheet(s) updated"
End Sub