How to Inherit Attachments on web

Hi.

I need some help on copy files from one document to another on web.

I have a form (Form1) with many fields and 6-7 file upload controls.

“Formulas Inherit values from selected document is enabled”

I have a button “Copy” which composes the same form (Form1). when clicked I need to copy information from the currently opened form with the data entered into the new document (Inheriting) that is created when COPY is clicked. how can copy (inherit) the attachments which are attached to the existing document to the new document.

I dont know how to achieve this in web. Please help me in case any of you have done this earlier.

Thanks in Advance

LN

Subject: How to Inherit Attachments on web

as far as I can seeinheriting attachments will not work automatically.

You will have to program the copying

of the attachments to the newly created doc.

Either detach the file and attach it

to the new doc or try to copy the

$File fields to the new document.

Subject: RE: How to Inherit Attachments on web

Hi.

I tried to use the $file fields but attachments are not getting inherited. I have some 5 computed fields and 5 editable text fields along with 3 file upload controls.

I tried using copyallitems method but I cannot change the computed values.

Since I dont need to copy all the fields, copyallitems is not suitable in this scenario.

If any of you have done this previously, please let me know. Looking forward for your valuable suggestions.

Subject: RE: How to Inherit Attachments on web

This procedure copies file attachments from the current Web document to an existing document (but it can be modified to work for the Notes client as well just by changing the docSource object). There is no direct way to copy file attachments – copying the $FILE item with CopyItemToDocument and using doc.ReplaceItemValue do not work on $FILE items. Using doc.CopyAllItems works, but that is not desirable, as I only want to copy the attachments.

The normal workaround is to detach attachments from the source document to the hard drive and re-attach them to a rich text field on the target document. However, that’s often restricted on a server, so I’d like to avoid it.

Here is a better strategy:

  1. Call the function below, passing in the database handle along with the source document and target document objects.

  2. Create new docTemp as blank document.

  3. Copy all items from docSource to docTemp.

  4. Loop through docTemp and delete all items not named $File. Now you have a docSource that only has the attachment(s) on it!

  5. RemoveItem($File) from docTarget (to clear existing attachments).

  6. Call docTemp CopyAllItems to docTarget (this should only copy the attachment).

  7. Save docTarget.

Code:

Sub CopyAttachments (db As NotesDatabase, docSource As NotesDocument, docTarget As NotesDocument)

Dim docTemp As NotesDocument

'Remove all attachments from existing document

Call docTarget.RemoveItem (“$FILE”)

'Create a temporary document and use CopyAllItems from the current document

'because I know that will include the attachment

Set docTemp = db.CreateDocument

Call docSource.CopyAllItems (docTemp)

'Clear all items not named $File from the temp docSource, so that all that’s left is the attachment

Forall item In docTemp.Items

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

docTemp.RemoveItem (item.Name)

End If

End Forall

'Now, docTemp only has the attachments left on it

'CopyAllItems will copy the attachment, so use it to copy to docTarget

Call docTemp.CopyAllItems (docTarget)

Call docTarget.Save (True, False)

End Sub

Subject: -BRILLIANT!!!- How to Inherit Attachments on web

I love this solution!!! It is brilliant in its simplicity to solve this issue which I have struggled with time and again. Well done Mic on such a creative and yet straight forward approach to this one.I know its been years since you posted this, but thanks.

Subject: How to Inherit Attachments on web

Here is a solution that works for me on the web. It could probably be adapted for the Notes client.

In the form you wish to copy files into make sure that the form properties box includes …

  1. Formula inherits values from selected document.
  • This will allow you to pass values from specified fields.
  1. Inherit entire selected document into rich text field (body as RichText)
  • This will pass the entire document to a RichText field including any attached files.

The next step is to include the following in the “WebQueryOpen” event …

@If( @IsNewDoc; @SetField(“Body”; “” ); “” )

  • this will clear the body content on new document but leave the attached files from the original as files are stored in a $File field.

Finally to create the copy you will need to create an appropiate link for example …

Create User Info Page

The ParentUNID parameter is the Unique ID of the document you wish to copy.

@Text(@DocumentUniqueID)”

That should be it.

Cheers!