0

我正在尝试为 Lotus Notes 中的表单编写日志记录系统,但我不确定如何附加有关在日志字段中更改的字段的信息。我使用了 3 个字段 Log_Date(日期)、Log_User 和 Log_Actions(文本,允许多个值)。

我想如果我在日志字段中添加逗号,它将在显示表单时创建一个新行,但我仍然在案例 2 行上遇到类型不匹配。

如何将新值附加到日志字段?

Sub Querysave(Source As Notesuidocument, Continue As Variant)
    ' Compare the values in the form after it is saved with its original values when the document is not a new document.    
    Dim doc As NotesDocument
    Set doc = Source.Document

    Dim session As New NotesSession
    Dim user As String
    user = session.CommonUserName

    If newDoc Then
        doc.Log_Date = Now()    
        doc.Log_User = user
        doc.Log_Actions = "New document created."
    Else        
        ' Load fields value to the array
        lastValues(0) = doc.QCR_No(0)
        lastValues(1) = doc.QCR_Mobile_Item_No(0)
        lastValues(2) = doc.QCR_Qty(0)

    ' Compared each value in the array to see if there is any difference
        Dim i As Integer
        For i = 0 To 2
            If lastValues(i) <> originalValues(i) Then
                Select  Case i
                Case 2 : doc.Log_Actions = doc.Log_Actions & "," & "Field QCR_Qty is changed"
                End Select
            End If
        Next
    End If
End Sub
4

3 回答 3

2

doc.Log_Actions返回注释项。要访问您需要使用的值doc.Log_Actions(0)

于 2012-01-30T21:18:18.030 回答
2

在 LotusScript 后端类(例如 NotesDocument、NotesItem)中,多值字段由数组表示,数组的每个元素都有一个值。对于设置字段的值,doc.Log_Actions 是用于分配数组的第一个(即零下标)元素的简写(他们在 Domino Designer 帮助中称其为“扩展语法”),但这不适用于获取价值。要获得第一个值,您必须使用 doc.Log_Actions(0)。要获取或设置第二个值,您必须使用 doc.Log_Actions(1)。

因此,您的案例 2 代码可能如下所示:

doc.Log_Actions(1) = "Field QCR_Qty is changed"

然而,我的猜测是,您真的希望能够在每次运行此代码时不断地追加到值列表的末尾。如果(出于任何原因!)文档中不存在 Log_Actions 项,您还希望您的代码是健壮的并且不会对您造成影响。为此,您将要这样做:

dim actionsItem as NotesItem
if doc.hasItem("Log_Actions") then
   set actionsItem = doc.getFirstItem("Log_Actions")
   call actionsItem.AppendToTextList("Field QCR_Qty is changed")
end if
于 2012-01-30T21:55:04.643 回答
1

或者,

If (Not doc.HasItem("LogActions")) Then
  doc.LogActions = "Field QCR_Qty is changed"
Else
  doc.LogActions = ArrayAppend(doc.LogActions,"Field QCR_Qty is changed")
End If

这等效于NotesItem方法 by rhsatrhs,您使用的方法是偏好问题。

于 2012-03-02T21:13:08.643 回答