How do i transfer attachment from one document to another

I need to transfer attachment on one document to a another document using lotuscript. the forms of both the documents are different. say form A document is opened on web and then from here i trigger a agent which saves the attachement on Form A to DOcument created with Form B

Please help

Subject: How do i transfer attachment from one document to another

Umm.Answer 1)

Search the forum for the many hundreds of times this question has been asked!

Answer 2)

Try using this code:

Dim w As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim docA As NotesDocument

Dim rtitemA As Variant

Dim rtitemB As Variant

'new Dims

Dim rtitemC As Variant

Dim rtitemD As Variant

'extra new Dims

Dim rtitemE As Variant

Dim rtitemF As Variant

'Dim session As New NotesSession





Set uidoc = w.CurrentDocument



'Call uidoc.Refresh( True )	

Set docA = uidoc.Document



'=======Naughty code===============

'Dim aaerror As Variant	

'aaerror = docA.GetItemValue("Error" )

'If Cstr(aaerror(0))="Yes" Then 

	'Messagebox "Error with first one"

'	Exit Sub

'End If

' ========End Naughty code===================

'Call uidoc.Save

docA.Documentation1_1 = ""

docA.Documentation2_1 = ""

docA.Description_1 = ""

Set rtitemA = docA.GetFirstItem( "Documentation1_1" )

Set rtitemB = docA.GetFirstItem( "Documentation1" )

If ( rtitemA.Type = RICHTEXT And _

rtitemB.Type = RICHTEXT ) Then

	Call rtitemA.AddNewLine(1)

	Call rtitemA.AppendRTItem( rtitemB )

	docA.attachments = " "

Subject: RE: How do i transfer attachment from one document to another

This code will not work for web. My form is on web so it doesn’t have any rich text field but a file upload control. More over i don’t want to save Form A. Just want to transfer the upload file to document with form B

Subject: RE: How do i transfer attachment from one document to another

I’m sure Shweta has solved this but for latecomers trying to solve similar problems…

I have a web form with - thanks to www.the-stickman.com - multiple File Upload controls (hint: to successfully save the multiple fields, your Javascript should read the name of the control you placed on the form and re-use it for each additional control it creates). I use the same web form to create “addendums” to the original (via “&ParentUNID=”) and want the previous attachments pre-loaded whenever I create a new addendum.

Below is the core logic of the WebQueryOpen agent associated to the form.

Note:

ac_ = AgentContext

i__ = int

nd_ = NotesDocument

ni_ = NotesItem

s__ = String

v__ = Vector

(all lower-case because they’re local variables in my app)

ac_WebServer = getSession().getAgentContext();

nd_BeingOpened = ac_WebServer.getDocumentContext();

// Get the ParentUNID from the field hosting the CGI variable QUERY_STRING_DECODED

s__QueryStringDecoded = nd_BeingOpened.getItemValueString( “QUERY_STRING_DECODED” );

// Because getItemValueString(…) DOES rarely return null…

i__IndexOf = (s_QueryStringDecoded == null ? “” : s__QueryStringDecoded.toLowerCase()).indexOf( “parentunid=” ) + 11; // 11 skips past “=” if found; otherwise 11 plus -1 = 10

if( i__IndexOf >= 11 )

{ s__ParentUNID = s__QueryStringDecoded.substring( i__IndexOf, i__IndexOf + 32 );

nd_Parent = ac_WebServer.getCurrentDatabase().getDocumentByUNID( s__ParentUNID );

if( nd_Parent != null )

{ v__ParentItems = nd_Parent.getItems();

for( int i = 0; i < v__ParentItems.size(); i++ )

{ ni_Attachment = (Item) v__ParentItems.elementAt( i );

  if( "$FILE".equalsIgnoreCase( ni_Attachment.getName() ) )

    nd_BeingOpened.appendItemValue( "$FILE", ni_Attachment );

}

}

}

To solve Shweta’s problem, I would put similar code in a WebQuerySave agent, where I’d retrieve the desired document (instead of nd_Parent). To be sure document A doesn’t get saved, set its SaveOptions field to “0” (either in the form or the agent).

Subject: How do i transfer attachment from one document to another

hi,

well the question is to transfer that is move or if copy

i suppose u have two rich text field on those document

where in u can copy or may do @dblookup to get the attachment from the view if there is a view made for Form A

else copy the $file see document properties in notes to get the attachment in the document, u can use copy item by searching for the EMBEDATTACH property of the document and if exist a $file then copy to the document of ur choice,

may this info can help.

Subject: RE: How do i transfer attachment from one document to another

My attachment on Form A doesn’t get saved. Without saving the attachment on Form A i want it to transfer to document with Form B