Notes UI Document - Adding\Removing a File in a Field

Domino/Notes Version: 12
Operating System: Windows 10
Client (Notes): 12.0.2FP2

Problem/Query:
I can add an attachment to an Rich Text Field with the following code:

@Command([EditGotoField]; "FileAttach");
@Command([EditInsertFileAttachment]; FilePath)

Is there any way to replicate this via Lotusscript? I believe the answer is no if for the NotesUIDocument.

I know I can do it via NotesRichTextItem and Embeddedobjects however this doesn’t work via the NotesUIDocument. I can set it up via an agent or an action that will add the file to the field.

Thanks in advance.

@mdub

You are correct that in LotusScript we have " EmbedObject" method to play with attachments.

However it has following limitation:

“In an open document in edit mode (the NotesDocument via NotesUIDocument.Document), changes made to rich text will not appear on screen immediately as they would with fields of other types. There is no method to cause this update to occur. You must close and reopen the document to see changes.”

Probably, you can use LotusScript to auto close and auto reopen the document after the attachment is attached.

it’s possible:

  1. create form called “fAttachFile”
    in QueryOpen :
    @Command([EditGotoField];@Environment(“fieldToAttachTo”));
    @Command( [EditInsertFileAttachment] ;@Environment(“fileToAttach”); “1”;“1”)
    use a SubForm with QueryOpen continue = false so the form never opens

  2. to attach the file from LotusScript…
    Sub attachFileToField(fileName As String, fieldName As String)
    Dim ws As New NotesUIWorkspace
    Dim session As New NotesSession
    Dim tempDoc As NotesDocument

    Set tempDoc = session.CurrentDatabase.CreateDocument
    tempDoc.form = “fAttachFile”

    Call session.SetEnvironmentVar(“fileToAttach”,fileName,False)
    Call session.SetEnvironmentVar(“fieldToAttachTo”,fieldName,False)

    On Error Resume Next ’ get user defined error if this isn’t here
    ws.EditDocument false,tempDoc,True,False,true ’ @Formula in queryOpen attaches the file

End Sub

Thank You for the responses. The Lotusscript UI and File interaction is a bit frustrating.

I decided to continue using the @Command and @PostedCommand for my UI needs.

Maybe this can be resolved in the future.