2012-01-24 47 views
0

我想要爲每個日期字符串實例創建一個文檔。LotusScript函數不會更新字段

然而,這並不如我所希望的那樣工作 - 該字段沒有更新,調試器根本沒有顯示任何東西。

有人可以用我的代碼指向正確的方向嗎?

Public Sub co_multiDates() 

'Basic Error Handler function 
'On Error GoTo errorHandler 
'errorHandler: MsgBox("ERROR " & CStr(Err) & ": " & Error$ & " on line " & CStr(Erl)) 

'Everything below this is designed to populate a field that then populates a column with multiple date values 
'This is designed so that when creating a location record for multiple days, there will be multiple entries in the employee's view 
Dim w As New NotesUIWorkspace  
Dim multiStartDate As NotesDateTime 
Dim multiEndDate As NotesDateTime 
Dim tempDate As NotesDateTime 
Dim dateArray() As NotesDateTime 
Dim dateCounter As Integer 
Dim AdjustDay As Integer 
Dim Source As NotesUIDocument 
Set Source = w.CurrentDocument 
Dim thisDoc As NotesDocument 
Set thisDoc = Source.Document 

' populate multiStartDate and multiEndDate with the values from the StartDate and EndDate fields 
Set multiStartDate = New NotesDateTime(thisDoc.GetItemValue("StartDate")(0)) 
Set multiEndDate = New NotesDateTime(thisDoc.GetItemValue("EndDate")(0)) 

'assign null value to dateCounter - calculates the difference between StartDate and EndDate 
Let dateCounter = 0 

While multiStartDate.TimeDifference(multiEndDate) <= 0 

    'add to MultiDates 
    ReDim Preserve dateArray(0 To dateCounter) 
    Set tempDate = New NotesDateTime(multiStartDate.DateOnly) 
    Set dateArray(dateCounter) = tempDate 

    'add 1 to the date to loop 
    Call multiStartDate.AdjustDay(1) 
    dateCounter = dateCounter + 1 
Wend 

'Replaces the value of the MultiDatesArray field in newDoc (current document) with the value of dateArray 
Call thisDoc.ReplaceItemValue("MultiDates", dateArray) 

'Updates audit trail field with any changes 
Call SetAuditTrail(w.CurrentDocument.document, "auditTrailField", 1, "PersonName", "Person Name") 

End Sub 

我覺得我可能錯過了一些非常明顯的東西。

謝謝。

回答

1

基於您正在使用UI類和更新文檔的事實,我假設您在Notes客戶端中從編輯模式下打開的文檔運行此代碼,所以我在該上下文中進行了測試通過將上面的子代碼添加到具有StartDate,EndDate和Multidates字段的表單中,並從該表單上的按鈕的Click事件中調用它。它將StartDate和EndDate之間的每個日期添加到字段Multidates,這似乎正是它的預期目的。

如果要在範圍內的每個日期創建一個文件,你需要你的While循環做內添加代碼,如:

' In your declarations... 
Dim session as NotesSession 
Dim thisDatabase as NotesDatabase 
Set thisDatabase=session.CurrentDatabase 

' In your loop... 
Set newDoc=thisDatabase.CreateDocument 
newDoc.Form="ChildForm" ' or whatever 
newDoc.myDate=dateArray(dateCounter) 
' Do other stuff to the document, then... 
Call newDoc.Save(False, True) 

如果我的任何上述假設都關閉,編輯你的問題與關於上下文的更多細節,你會得到更好的答案。

+0

你是正確的搶劫,我需要把一個循環內循環。我需要使用一個循環來檢測字段中的多個值,然後對於每個值,循環訪問日期數組以創建每個日期的新文檔。謝謝你的幫助! – Thomas

+0

很高興幫助!請接受或評價對您有幫助的答案。 –

0

我不知道這是什麼功能應該做的:Call SetAuditTrail(w.CurrentDocument.document, "auditTrailField", 1, "PersonName", "Person Name")

但在代碼的其餘部分我沒有看到任何保存當前和/或創建一個新文件中。 thisDoc.save(false,true)可能會有所幫助。

我看不出爲什麼調試器不會運行此代碼。