LotusScript函数不更新字段

时间:2012-01-24 13:54:50

标签: function date lotus-notes 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

我觉得我可能遗漏了一些非常明显的东西。

感谢。

2 个答案:

答案 0 :(得分:1)

基于您正在使用UI类和更新文档的事实,我假设您在Notes客户端中从在编辑模式下打开的文档中运行此代码,因此我在该上下文中通过将上面的Sub代码添加到包含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)

如果我的上述任何假设都已关闭,请使用有关上下文的更多详细信息编辑您的问题,您将获得更好的答案。

答案 1 :(得分:0)

我不确定这个函数应该做什么:Call SetAuditTrail(w.CurrentDocument.document, "auditTrailField", 1, "PersonName", "Person Name")

但是在其余的代码中,我没有看到当前和/或创建新文档的任何保存。 thisDoc.save(false,true)可能有帮助。

我认为调试器没有理由不运行此代码。