在另一个数据库中创建文档并设置字段值

时间:2014-09-12 07:06:50

标签: lotus-notes lotus-domino lotusscript lotus domino-designer-eclipse

我的目标是从另一个数据库中的一个数据库创建一个文档,并使用源数据库中的值填充这些字段。我能够连接到其他数据库并撰写文档,但无法进行编辑。

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

当我打电话

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

我收到一条错误消息,提示我必须在编辑模式下打开文档。当我尝试使用

更改编辑模式时
uidoc.EditMode = True

我收到错误消息"文档命令不可用"。有人可以帮我吗?

1 个答案:

答案 0 :(得分:2)

这是可能的,采取后端而不是前端类

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