Editing attachments with Lotus Script

Hi,

Can anyone help me with finding a solution to editing an attachment directly from a Notes form. I’ve read through some old posts and it seems as through I need to detach the file, open the file, make changes and then save the document back to the form. I’m fine with detaching the file and opening it, but am stuck in how I then attach the file back AFTER the user has made changes. I also tried using the .activate method, but it seems this can only be used for embedded objects, not attachments. My sample code is shown below:

Function EditBriefDocument(COAGDocument As NotesDocument) As NotesDocument

 'CreatebriefDocument



 'Parameters

 'COAG Document : The Document that the brief is being created for.



 'Description

 'This function will create/edit a brief document for the specified COAG document.

Dim BriefTemplate As Variant

Dim OutputPath As String



Dim LeadBranch As String

Dim Branchheads As Variant



Dim PolicyOfficerNo As String

Dim BranchManagerNo As String





Dim Session As New NotesSession

Dim  BriefDocument As NotesDocument

Dim BriefEmbeddedField As NotesRichTextItem



Dim WorkSpace As New NotesUiWorkSpace

Dim AuthorsList As NotesItem

Dim ReadersList As NotesItem



If BriefExists(COAGDocument, BriefDocument) Then

	If Not BriefDocument Is Nothing Then

		Set EditBriefDocument = BriefDocument

’ Exit Function

	End If

End If



Dim myApp As Variant	

Set myApp = CreateObject("Word.Application")	



	'Hiding word from the user

myApp.Visible = True



Dim ExtractDir As String



ExtractDir = Environ$("TEMP")

If ExtractDir = "" Then ExtractDir = Environ$("TMP")



If ExtractDir = "" Then

	Msgbox "No temporary directory is specified with the TEMP or TMP environment variables", 16, "Error"

’ GetTempDirs = “”

End If



 ' terminate with \

If Right$(ExtractDir, 1) <> "\" Then

	ExtractDir = ExtractDir & "\"

End If



Dim rtitem As Variant

Dim sfile As String



Set rtitem = editbriefdocument.GetFirstItem("BriefDocument")

Forall o In rtitem.EmbeddedObjects

	If ( o.Type = EMBED_ATTACHMENT ) Then

		sfile = o.source

		Call o.ExtractFile( ExtractDir & sfile )

		Call o.remove

	End If

	

End Forall



OutputPath = ExtractDir & sfile

myApp.Documents.Open OutputPath





Set BriefEmbeddedField = New NotesRichtextItem(BriefDocument,"BriefDocument")

Call BriefEmbeddedField.EmbedObject (EMBED_ATTACHMENT, "", OutputPath)

Call BriefDocument.Save(False,False)

End Function

Subject: RE: Editing attachments with Lotus Script

How to use LotusScript to create a file attachment in the front end.

But there are @Commands for editing attachments – can’t you use that? If you have to have some script you can call a script agent from your formula.

Subject: RE: Editing attachments with Lotus Script

Hi Andre,

I’m not having trouble attaching a file, I’m having trouble editing an attachment that’s currently on a form.

For example, I have a button which the user will click and which I then want to open the exisinting Word attachment, let the user edit the document and once they close out of the document, to save it back into the Notes form as an attachment.

I’m able to extract the attachment to a file location, but how do I then have this document copied back to Notes once they save/close the Word document? Or is there, as you say, @Commands to edit the file directly from Notes?

cheers,

jason

Subject: RE: Editing attachments with Lotus Script

Attachments are editable in place. That is, the user opens the document, opens the attachment, edits the attachment, then saves. The user will then be prompted to save the Notes document, whereupon the current attachment will be replaced by the working version in the temporary file location. This requires no additional coding on your part.