How to transfer a NotesDocument into a NotesDocumentCollection?

Hello,

I have a NotesDocument, which is the DocumentContext (web). In a WebQuerySave, I want to convert that NotesDocument to a NotesDocumentCollection.

Here’s my code (after looking around on this forum) :

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Dim doc As NotesDocument

Set doc = session.DocumentContext

Dim dc As NotesDocumentCollection

'For unknown reason, before adding a document, the DC must be initialized to something

Dim view As NotesView

Set view = db.GetView(“va_all”)

Set dc = view.GetAllDocumentsByKey(“%dummy$”, True)

Call dc.AddDocument(doc)

However, it always generate an error on the “AddDocument” line (“Invalid Note ID”).

I suspect this might happen because this code runs on the WebQuerySave event and that my document has never been saved yet.

I want to convert the web context document to a NotesDocumentCollection because I have to call an existing function that requires this type as the only parameter.

Is there a way to do this? (convert a NotesDocument to a NotesDocumentCollection containing only one doc)

Thanks!

Subject: How to transfer a NotesDocument into a NotesDocumentCollection?

I think you are right about the cause. I have had to do this kind of thing before, but not with an unsaved document. Note that the documentation states that you should NOT explictly save a context document in a Web Query Save agent…

If you are really stuck with this interface, you might want to do the following (its horrible, I know)…

  1. Clone the context document.

  2. Save the copy.

  3. Add it to your empty document collection and call your function.

  4. Copy the results from your clone back to the original context document.

  5. Let the Web Query Save agent save your context document.

Subject: How to transfer a NotesDocument into a NotesDocumentCollection?

Subject: RE: How to transfer a NotesDocument into a NotesDocumentCollection?

If I try this from the web with agent document selection set to “None”, I don’t seem to get a collection. The documentation doesn’t say that it doesn’t work on the web, but I have never been able to use it. Am I doing something wrong?

The code below results in “Nope” and “Got Context” when run from a new web document (either by URL or WebQuerySave).

Dim session As New NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument

If Not (doc Is Nothing) Then

Print “Got Collection”

Else

Print “Nope”

End If

Set doc = session.DocumentContext

If Not (doc Is Nothing) Then

Print “Got Context”

Else

Print “Nope”

End If

Subject: RE: How to transfer a NotesDocument into a NotesDocumentCollection?

Same here!My agent is run from “Agent list selection” and target is “None”… I receive a NotesDocumentCollection of 0 document (dc.Count = 0).

I’m using a similar code to Andrew. Are we doing something wrong?

Thanks for your explanation about NotesDocumentCollection… now it makes more sense!

Subject: RE: How to transfer a NotesDocument into a NotesDocumentCollection?

Subject: RE: How to transfer a NotesDocument into a NotesDocumentCollection?

Thanks to you Willy and Andrew, this is what I was afraid of.