Copy attachment to another document in web

Create document A in web, using File Upload to attach file(s), then press a ‘New Order’ button to create another document B(which is Resoponse, inherit vlaues from A), in WebQueryOpen of document B, agent to copy $FILE of A to B, after document B open, I can see the attachment at the bottom of B, but after press ‘Save’ button in B, the attachment is gone.there is not Rich Text field in A and B, but in A, $FILE contains attachments.

‘new Order’ button in A:

@Command([FileSave]);

@Command([FileCloseWindow]);

@Command([Compose] ; “Document B”)

‘Save’ button in B:

@Command([FileSave]);

@Command([ViewRefreshFields])

code in WebQueryOpen in B:

Sub CopyAttachments (cdb As NotesDatabase, docA As NotesDocument, docBAs NotesDocument)

Dim docTemp As NotesDocument

Call docB.RemoveItem (“$FILE”)

Set docTemp = cdb.CreateDocument

Call docA.CopyAllItems (docTemp)

Forall item In docTemp.Items

If Not (Ucase(item.Name) = “$FILE”) Then

  docTemp.RemoveItem (item.Name)

End If

End Forall

Call docTemp.CopyAllItems (docB)

Call docB.Save (False,True)

I’ve use ExtracFile and same rich t ext field in both A and B, get same issue.

Any help is appreciated in advance!

Subject: Copy attachment to another document in web…

First, I don’t think your supposed to call save in WebQueryOpen. I also don’t think you need the temp doc. How about something like this?

Sub CopyAttachments (docA As NotesDocument, docB As NotesDocument)

Dim itemB as NotesItem

Forall itemB In docB.Items

	If itemB.type = ATTACHMENT Then

		Call itemB.Remove

	End If

End Forall



Dim itemA as NotesItem

Forall itemA In docA.Items

	If itemA.type = ATTACHMENT Then

		' Get the attachment.

		Dim attachedFile As NotesEmbeddedObject

		Set attachedFile = docA.GetAttachment(itemA.values(0))

		

		' Copy the item

		Call docB.CopyItem( itemA, attachedFile.Name)

	End If

End Forall

End Sub

Subject: Copy attachment to another document in web…

I didn’t read the first part closely enough. If you just composed docB why do you need to clear it’s attachments? They can only be the ones from docA, right? Then we go and copy the docA attachments right back to docB.

I’m also skeptical of doing this is WebQueryOpen. Why not do it in the WebQuerySAVE of docA?

Create docB, make it a response.

Copy all items from docA.

Save docB. (DON’T save docA)

Print the link to this new doc (overriding the $$Return on docA)

Subject: Thanks, it works,

Brian, thanks a lot for your advises.It works well now. my old post involved to get existing document(B),so need to remove old attachments.

Thanks again.