Lotus notes 从配置文件文档获取值

Lotus notes 从配置文件文档获取值,lotus-notes,lotusscript,Lotus Notes,Lotusscript,从配置文件文档中获取值时遇到问题。对于创建,我遵循以下说明: 创建配置文件表单 1.创建一个包含字段的表单,以保存要存储在配置文件文档中的值。 2.选择设计-表单属性并取消选择“包含在菜单中”和“包含在搜索生成器中” 3.保存表单。 4.不要在任何视图中包含表单 在形式I中,只有一个字段在组成时进行计算(一个数字),计算值为“0” 但使用此代码,我无法检索字段值: Dim session as New NotesSession Dim db as NotesDataba

从配置文件文档中获取值时遇到问题。对于创建,我遵循以下说明: 创建配置文件表单 1.创建一个包含字段的表单,以保存要存储在配置文件文档中的值。 2.选择设计-表单属性并取消选择“包含在菜单中”和“包含在搜索生成器中” 3.保存表单。 4.不要在任何视图中包含表单

在形式I中,只有一个字段在组成时进行计算(一个数字),计算值为“0”

但使用此代码,我无法检索字段值:

Dim session as New NotesSession             
Dim db as NotesDatabase             
Dim doc as NotesDocument                
Set db=session.CurrentDatabase              
Set doc=db.GetProfileDocument("nameofprofiledoc")
dim number as integer
number=doc.fieldname(0)

Isprofile返回true,但数字始终为“”。由于某些原因,它从未获得值

可能是因为您尚未将文档保存到数据库中。您可以创建一个操作按钮,让您编辑文档,然后保存它:

@Command( [EditProfile] ; formname );

调用GetProfileDocument时不会执行计算字段公式。这是因为GetProfileDocument是一个“后端”方法。“前端”使用该表单及其各种字段定义和公式。(有一个例外:后端类中有一个ComputeWithForm方法可用。)无论如何。GetProfileDocument要么加载以前保存的配置文件文档,要么创建一个基本为空的新配置文件文档。@Ken的回答告诉您如何手动创建配置文件文档并保存它,以便您的代码可以找到它。或者,您可以在代码中执行如下初始化:

if ! doc.hasItem("fieldname") then
  doc.replaceItemValue("fieldname",0)
end if
number=doc.fieldname(0)

这样,您就不会依赖于手动创建概要文件文档的人员。但是,如果您从代码中的多个位置访问概要文件文档,并且无法预测可能首先执行哪些代码,那么您可能会希望创建一个包含函数(或类)的脚本库并在您自己的函数(或方法)中包装GetProfileDocument,以确保所有代码路径都能正确初始化。

正如Richard提到的,当您调用方法
GetProfileDocument
时,如果在数据库中找不到该配置文件,则会将其创建为空白文档,(它只有一些初始字段,其中包含配置文件名称、冲突操作、最后一个编辑器)

要初始化配置文件,您可以尝试以下操作之一: 1) 编程表单的QuerySave事件以将所有项目复制到配置文件(然后取消保存,以避免将数据存储在常规文档中)

或: 2) 调用
GetProfileDocument
创建一个新的配置文件或获取一个旧的配置文件(您可以通过检查
IsNewNote
属性来区分差异。然后为其指定一个表单名称,并使用此表单计算它

在代理人或行为中:

Sub InitializeProfile
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim profile As NotesDocument

    Set db = s.CurrentDatabase
    Set profile = db.GetProfileDocument("MyForm")

    If profile.IsNewNote Then
        Call profile.ReplaceItemValue("Form", "MyForm")
        Call profile.ComputeWithForm(False, False)    'This will create the computed fields with their default values in the profile.
        Call profile.Save(True, False)
    End If
End Sub
Sub InitializeProfile
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim profile As NotesDocument

    Set db = s.CurrentDatabase
    Set profile = db.GetProfileDocument("MyForm")

    If profile.IsNewNote Then
        Call profile.ReplaceItemValue("Form", "MyForm")
        Call profile.ComputeWithForm(False, False)    'This will create the computed fields with their default values in the profile.
        Call profile.Save(True, False)
    End If
End Sub