Hello. I am trying to utilize an agent which is executed via a WebQuerySave event. The agent should copy docs selected via a view (and all child docs) to a different database. I have successfully accomplished this task via a LotusScript agent from the client, however, I am having difficulty doing similar via a browser (WQS). Not sure how to process the selected docs via UNID and copy them. Included is the code for the LS button that works via the client so you can see what I am trying to accomplish. Any help would be greatly appreciated.
Sub Click(Source As Button)
Dim s As New notessession
Dim ws As New NotesUIWorkspace
Dim view As NotesUIView
Dim thisdb As notesdatabase
Dim dc As notesdocumentcollection
Dim doc As NotesDocument, child As NotesDocument, newDoc As NotesDocument, newChild As NotesDocument
Dim responses As NotesDocumentCollection
Dim docX As NotesDocument
Dim otherdb As New NotesDatabase( "", "" )
Call otherdb.Open( "server", "db.nsf" )
Set thisdb = s.currentdatabase
Set dc = thisdb.unprocesseddocuments
Set view = ws.CurrentView
If dc.Count<1 Then
Msgbox "You must select at least one document to transfer. Please try again."
Exit Sub
End If
Set doc = dc.GetFirstDocument
Do While Not (doc Is Nothing)
doc.OriginalUNID = doc.UniversalID
Call doc.Save(True, False)
Set newDoc = doc.CopyToDatabase(otherdb)
'transfer doc children, if any
If doc.Responses.Count > 0 Then
Set responses = doc.Responses
Set child = responses.GetFirstDocument
'get handle on child doc in source db
Do While Not(child Is Nothing)
child.OriginalUNID = child.UniversalID
Call child.Save(True, False)
Set newChild = child.CopyToDatabase(otherdb)
Call newChild.MakeResponse(newDoc )
Call newChild.Save(True,False)
Set child = responses.GetNextDocument(child)
Loop
End If
Set docX = dc.GetNextDocument(doc)
Call doc.Remove(True)
Call ws.ViewRefresh
Set doc=docX
Loop
End Sub