Search code examples
lotus-noteslotus-dominolotusscriptlotusdomino-designer-eclipse

Create a document in another database and set the field values


My goal is to create a document from one database in another database and fill the fields with values from the source database. I was able to connect to the other database and compose a document but editing is not possible.

Sub Click(Source As Button)

Dim mydb As NotesDatabase
Dim workspace As NotesUIWorkspace 
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument

Dim Server As String 
Dim DBPath As String 
Dim DBForm As String

'----------------------------------------------------------------- 
' Set target database information 
'-----------------------------------------------------------------
Server = "Server"
DBPath = "Path"
DBForm = "Form"

'----------------------------------------------------------------- 
' Attempt connection to target server
'-----------------------------------------------------------------
Print "Connecting to target database"
Set mydb = New NotesDatabase("", "") 
Call mydb.Open(Server, DBPath)  

If (mydb.IsOpen) Then 
    '-----------------------------------------------------------------
    ' Create new document 
    '-----------------------------------------------------------------
    Print "Connection established to: " + mydb.FileName 
    Set workspace = New NotesUIWorkspace 
    Print "Composing change management record" 
    Set uidoc = workspace.ComposeDocument (Server, DBPath, DBForm)

    Call uidoc.FieldSetText("FIELD", "12345")
Else
    Msgbox "Warning: unable to open target database." 
End If      

End Sub

When I'm calling

Call uidoc.FieldSetText("FIELD", "12345")

I'm getting an error message saying that I have to open the document in edit mode. When I'm trying to change the edit mode with

uidoc.EditMode = True

I'm getting the error message "Document command is not available". Can someone please help me here?


Solution

  • it is possible, take the backend not the frontend classes

    Dim workspace As New Notesuiworkspace
    Dim session As New NotesSession
    Dim myDb As NotesDatabase
    Dim doc As notesdocument
    
    Set myDb= session.Getdatabase("Server", "Path", false)
    If (mydb.IsOpen) Then 
    Set doc = myDb.Createdocument()
    doc.field="12345"
    
    
    Call workspace.Editdocument(true, doc)
    Else
    Msgbox "Warning: unable to open target database." 
    End If