LotusScript 函数不更新字段

发布于 2024-12-28 19:25:05 字数 1972 浏览 0 评论 0原文

我正在尝试为日期字符串的每个实例创建一个文档。

然而,这并没有像我希望的那样工作——该字段没有更新,调试器根本没有向我显示任何内容。

有人可以用我的代码指出正确的方向吗?

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

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

谢谢。

I'm trying to get a document to be created for each instance of a string of dates.

This however doesn't work as I'd hoped - the field doesn't update and the debugger doesn't show me anything at all.

Can someone point me in the right direction with my code?

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

I feel like I am probably missing something very obvious.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌梦深 2025-01-04 19:25:05

基于您正在使用 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)

如果我的上述任何假设不成立,请使用有关上下文和您的更多详细信息编辑您的问题会得到更好的答案。

Based on the fact that you are using UI classes and updating the document, I'm assuming that you are running this code in the Notes client from a document that is open in edit mode, so I tested it in that context by adding the above Sub code to a form with fields StartDate, EndDate and Multidates and called it from the Click event of a button on that form. It added every date between StartDate and EndDate to field Multidates, which seems to be exactly what its intended purpose is.

If you want to create a document for each date in the range, you need to add code within your While loop to do that, such as:

' 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)

If any of my above assumptions are off, edit your question with more details about the context and you will get a better answer.

森林很绿却致人迷途 2025-01-04 19:25:05

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

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

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

I am not sure what this function should do : Call SetAuditTrail(w.CurrentDocument.document, "auditTrailField", 1, "PersonName", "Person Name")

But in the rest of the code I do not see any save of the current and/or creation of a new document. thisDoc.save(false,true) might help.

I see no reason why the debugger would not run this code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文