I am trying to duplicate in LotusScript the exact results of doing “File>Attach” (for multiple files) in a new Memo and not having much success. I am looping through entries in a temp directory and trying to attach the files. In one attempt I did not see the attachments before I sent it, but after sending it to myself I did, however not with the icons of the files application (i.e. MS Word).
I believe this was the code for that attempt:
If uidoc.IsNewDoc Then
uidoc.AutoReload = True
Dim CurField As String
CurField = uidoc.CurrentField
If Not (CurField = "Body") Then
Call uidoc.Gotofield("Body")
End If
Dim doc As NotesDocument
Dim RT As NotesRichTextItem
Dim object As NotesEmbeddedObject
Dim filename As String, fullPath As String
Set doc = uidoc.Document
Set RT = New NotesRichTextItem( doc, "Body" )
'
filename$ = Dir$(Path + "\*.*", 0)
Do While fileName$ <> ""
fullPath$ = Path$ + "\" + fileName$
'Messagebox(fullPath$)
Set object = RT.EmbedObject( EMBED_ATTACHMENT, "", fullPath$)
fileName$ = Dir$()
Loop
A colleague of mine accomplishes something similar for one file where he stores a full file path and name in an environment value “Param1”, then calls a formula language agent with this code:
@If (@Environment(“Param1”) != “”; @Command( [EditInsertFileAttachment] ;
@Environment(“Param1”) ) ; @All)
I tried replacing the NotesRichtextItem.EmbedObject line in my script with:
Dim result As Variant
....
result = Evaluate({@Command( [EditInsertFileAttachment] ;fullPath$)})
This doesn’t seem to work at all. The result variable doesn’t even get a value when in step through in script debugger.
I am sure there must be a way to do this.
Thanks for any help.
Tony
Subject: Inserting file attachments to new memo in LotusScript
Hi.
I’m trying to insert an attachment to the Memo (as you) but I find it impossible to attach an attachment that is too in the form (into the .nsf).
Objective is to send to the internet a message as an attachment every time I send a mail.
Problem is $filepath: Only files on client side. ¿Is there a way to make attachments form server side?
I have tried too to make a richtextfield and put the attachment into it so I could copy this richtextfield at the end of the other, but I can’t put the attachment into this richtextfile. ¿Do you know how to do it?
Thanks
Subject: RE: Inserting file attachments to new memo in LotusScript
If possible, create the memo document in the back end and attach the attachments before you open the memo on-screen. That’s simpler.
As has been extensively discussed in this forum, changes you make to rich text don’t show up on screen until you close and reopen the document. This can be done without saving it using NotesUIDocument.Close and NotesUIDocument.EditDocument – if you search for Close and EditDocument in here I think you’ll find someone posted the code for that recently. Note also that to get the latest rich text contents you must use the Refresh method.
Or, you could do as your colleague has done and insert the attachments using macro language. The Evaluate statement, however, can;t be used to execute @Commands. You would have to have a macro language agent that used a looping construct – @For is probably the best choice here – to attach each file. The LS agent would store the list of filenames in a profile doc, and you would have to call both agents from your action, assuming you’re doing this with an action.
Subject: RE: Inserting file attachments to new memo in LotusScript
Assuming the Close and EditDocument(NotesUIWorkspace) works, I’m still not sure about how to do the attachment properly in LotusScript. I might not understand the Notes object model that well. If the Memo is new, there doesn’t appear to have a Field “Body” when I look at the doc properties, yet the Currentfield returns that (if my cursor is there). If I do a GetFirstItem(“Body”), my NoteItem or NotesRichTextItem remains null. What are the proper steps to fully add an attachment to a new Memo?
I will search for the code you mentioned, but the API documentation says that NotesUIDocument.Close will cause the user to be prompted for a save if changes had been made. In my case I wouldn’t want to lose addressee or subject data, but wouldn’t want the user to be prompted either.
Thanks
Subject: RE: Inserting file attachments to new memo in LotusScript
shows how to avoid the save dialog.
As I suggested before, read about the Refresh method to find out how to get the current contents of the rich text field in a newly composed document.
Subject: RE: Inserting file attachments to new memo in LotusScript
This is getting frustrating. Is this a limitation in Notes5.x. Trying uidoc.close. There is no argument for this function in 5.x, 6.x takes a boolean. Saving before the close doesn’t appear to have any affect. I’ve even tried copying all items to a new doc, deleting the old and doing ws.editdocument on the new. Too remove the old doc from the ws I had to set edit = False, and then do uidoc.DeleteDocument. I STILL get the close dialog prompt.
Also, since it is 5.x there is no @For for iterating. Since I know I had a formula agent that worked –
@If (@Environment(“Param1”) != “”; @Command( [EditInsertFileAttachment] ;
@Environment(“Param1”) ) ; @All)
---- I tried resetting the environment value to a different file name in each pass of a LotusScript loop and then tried to call the formula agent. I get “Notes Error: @Function is not valid in this context”
Can you not call a formula language agent from a LotusScript agent?
Subject: RE: Inserting file attachments to new memo in LotusScript
Ah well… since this is the Notes/Domino 6 forum, and since you didn’t specify, I naturally assumed you were using 6.0 or later.
I haven’t tried to do it with R5, but it should probably perhaps still work. Here’s some code:
Dim wksp As New NotesUIWorkspace
Dim doc As NotesDocument
uidoc.Refresh True ' get the up to date rich text
Set doc = uidoc.Document
doc.SaveOptions = "0"
uidoc.AutoReload = False ' so we can delete doc.SaveOptions later without getting "do you want to save" prompt
uidoc.Close
' add your attachments here
doc.RemoveItem("SaveOptions")
Set uidocNew = wksp.EditDocument(True, doc)
uidocNew.gotofield "Body"
I haven’t tried this in version 5 or 6 – just made it up on the spot, so caveat emptor. There’s some chance that the uidoc.Close, which in R5 technically doesn’t take effect until the script ends, might prevent EditDocument from opening a new window because the old window on the same document is still open (even though it’s doomed). If it doesn’t work, you could try to make sure what part doesn’t work by sticking in Exit Subs at different points. You might need to put a SaveOptions computed field on the form with a formula such as: @If(@IsDocBeingLoaded; @Unavailable; @IsAvailable(SaveOptions); SaveOptions; @Unavailable)
You do not need to save the document, and shouldn’t because the user’s not expecting it, so could lose data. This will either work without saving, or it won’t work even if you do save.
If you can’t get the LotusScript to work, you could use macro language – even without @For, you can repeat code the old way – by repeating code. You’d have a series of @If statements to check if there was another file to attach and if so, attach it. This limits the number of files you can attach at once to how many times you’re willing to repeat the code, but if the limit is high enough it shouldn’t be a problem.
If that’s not good enough – I don’t know what happens if you use Run to call a formula agent that uses @Commands – probably it doesn’t work, but if it did work, you could call the agent repeatedly to process many files.