2012-01-30 108 views
0

我正在嘗試在Lotus Notes中爲表單編寫日誌記錄系統,但是我不知道如何追加有關在日誌中更改的字段的信息領域。有3個字段使用Log_Date(日期),Log_User和Log_Actions(文本,允許多個值)。在Lotus Notes中使用多值字段

我想如果我將逗號添加到日誌字段,它將在顯示錶單時創建一個新行,但我仍然在案例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 

回答

2

doc.Log_Actions返回notesitem。要訪問您需要使用的值doc.Log_Actions(0)

+0

如果他將其作爲Log_Actions(0)來處理,並且不會更改代碼中的其他任何內容,那麼他​​將不會將其視爲多值項目。他只會用逗號分隔的列表創建單個值。如果他在Notes UI中打開文檔,編輯並保存該文檔,可能會導致出現奇怪的行爲。也就是說,如果該字段設置爲多值並帶逗號分隔符顯示,則保存操作將把它分解爲多個值,然後下一次他的代碼運行時,它將再次追加到第一個值。 – 2012-01-30 22:12:54

+0

絕對如此,我只處理類型不匹配錯誤。 – 2012-01-31 07:33:56

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 
+0

忘了提及..你會想要一個else子句創建缺少的NotesItem,然後賦值給第0個元素。 – 2012-01-31 01:18:51

+0

它說:「設置一個字段的值,doc.Log_Actions是簡寫...用於分配數組的第一個(即,零下標)元素」 - 但我認爲你可以分配一個完整的數組值.field = array,你會得到一個多值列表分配。如果你只想要一個值,然後從數組中選擇它(通常是第0個元素)doc.field = val(0) – andora 2014-07-24 09:29:48

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方法,通過rhsatrhs,你用的是偏好的問題。

+0

我喜歡arrayAppend扭曲 - 很好。 – 2013-11-21 20:51:50