LotusScript - 任何人都可以修复我的函数吗?

发布于 2024-12-18 00:41:56 字数 2352 浏览 2 评论 0原文

我正在尝试编写一个验证函数来检查数据集中是否已存在要添加的条目。

但搜索并没有找到它——我只能继续在数据库中输入相同的约会。

如果有人能找出我的代码不起作用的原因,我将不胜感激。

谢谢

Public Function checkNewLocationRecordIsUnique As Boolean

Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim db As NotesDatabase
Dim selectView As NotesView
Dim key(0 To 4) As Variant
Dim entry As NotesViewEntry
Dim entryIsNotUniqueMsg As String
Let entryIsNotUniqueMsg = "There is already an entry for this date/time. Please modify your entry's details or cancel the existing entry to continue."
Dim thisDoc As NotesDocument
Dim uiDoc As NotesUIDocument
Set uidoc = w.CurrentDocument
Set thisDoc = uidoc.Document

'get handle to database and check we've found the database
Set db = s.CurrentDatabase
If Not db Is Nothing Then

    'get handle to view to lookup field combination in
    Set selectView = db.GetView("allLocationRecordsByName")
    Call selectView.Refresh()

    If Not selectView Is Nothing Then

        'populate "key" - an array of variants - with fields to use as match criteria

    key(0) = thisDoc.PersonName
    key(1) = thisDoc.StartDate
    key(2) = thisDoc.EndDate
    key(3) = thisDoc.StartTime
    key(4) = thisDoc.EndTime
    Set entry = selectView.GetEntryByKey(thisDoc.key, True)

        'lookup the combination in the view to see if it already exists
        If entry Is Nothing Then
            MsgBox "No conflicting entry found! Record added.", 0, "Notice"

            'if it wasn't found then the record is unique so return true
            checkNewLocationRecordIsUnique = True
        Else
            'else the combination was found - but lets make sure that it's not this one
            '(this could happen if the user is editing an existing record)
            'compare uids of both thisDoc and the doc entry that was found

            If entry.document.UniversalID = thisDoc.UniversalID Then
                checkNewLocationRecordIsUnique = True
            MsgBox "An Entry Was Found, But It Was The Entry! Record added.", 0, "Notice"

                'else it WAS found as a separate document so the function returns false
            Else
                MsgBox entryIsNotUniqueMsg, 0, "Error: Entry Is Not Unique"
                    checkNewLocationRecordIsUnique = False  
            End If
        End If
    End If  
End If
End Function

I'm trying to write a validation function that checks to see if an entry being added already exists in the dataset.

But the search doesn't pick it up - i can just keep entering the same appointment into the database.

If anyone can spot why my code isn't working, i'd appreciate the help.

Thanks

Public Function checkNewLocationRecordIsUnique As Boolean

Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim db As NotesDatabase
Dim selectView As NotesView
Dim key(0 To 4) As Variant
Dim entry As NotesViewEntry
Dim entryIsNotUniqueMsg As String
Let entryIsNotUniqueMsg = "There is already an entry for this date/time. Please modify your entry's details or cancel the existing entry to continue."
Dim thisDoc As NotesDocument
Dim uiDoc As NotesUIDocument
Set uidoc = w.CurrentDocument
Set thisDoc = uidoc.Document

'get handle to database and check we've found the database
Set db = s.CurrentDatabase
If Not db Is Nothing Then

    'get handle to view to lookup field combination in
    Set selectView = db.GetView("allLocationRecordsByName")
    Call selectView.Refresh()

    If Not selectView Is Nothing Then

        'populate "key" - an array of variants - with fields to use as match criteria

    key(0) = thisDoc.PersonName
    key(1) = thisDoc.StartDate
    key(2) = thisDoc.EndDate
    key(3) = thisDoc.StartTime
    key(4) = thisDoc.EndTime
    Set entry = selectView.GetEntryByKey(thisDoc.key, True)

        'lookup the combination in the view to see if it already exists
        If entry Is Nothing Then
            MsgBox "No conflicting entry found! Record added.", 0, "Notice"

            'if it wasn't found then the record is unique so return true
            checkNewLocationRecordIsUnique = True
        Else
            'else the combination was found - but lets make sure that it's not this one
            '(this could happen if the user is editing an existing record)
            'compare uids of both thisDoc and the doc entry that was found

            If entry.document.UniversalID = thisDoc.UniversalID Then
                checkNewLocationRecordIsUnique = True
            MsgBox "An Entry Was Found, But It Was The Entry! Record added.", 0, "Notice"

                'else it WAS found as a separate document so the function returns false
            Else
                MsgBox entryIsNotUniqueMsg, 0, "Error: Entry Is Not Unique"
                    checkNewLocationRecordIsUnique = False  
            End If
        End If
    End If  
End If
End Function

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

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

发布评论

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

评论(3

七七 2024-12-25 00:41:57

thisDoc.PersonName 返回一个数组,您可能需要使用

key(0) = thisDoc.PersonName(0)
key(1) = thisDoc.StartDate(0)
key(2) = thisDoc.EndDate(0)
key(3) = thisDoc.StartTime(0)
key(4) = thisDoc.EndTime(0)

thisDoc.PersonName returns an array, you probably need to use

key(0) = thisDoc.PersonName(0)
key(1) = thisDoc.StartDate(0)
key(2) = thisDoc.EndDate(0)
key(3) = thisDoc.StartTime(0)
key(4) = thisDoc.EndTime(0)
谁与争疯 2024-12-25 00:41:57

您使用五行代码来填充名为 key 的本地变体数组,但实际上并未将该数组用于 GetEntryByKey 调用。

所以我的猜测是你希望代码这样说:

Set entry = selectView.GetEntryByKey(key, True)

而不是这样:

Set entry = selectView.GetEntryByKey(thisDoc.key, True)

You are using five lines of code to populate a local variant array called key, but you are not actually using that array for your GetEntryByKey call.

So my guess is that you want the code to say this:

Set entry = selectView.GetEntryByKey(key, True)

instead of this:

Set entry = selectView.GetEntryByKey(thisDoc.key, True)
仲春光 2024-12-25 00:41:57

视图 allLocationRecordsByName 是否按搜索键中包含的每一列进行排序?

请参阅 GetEntryByKey 文档。

Is the view allLocationRecordsByName sorted on each column included in the search key?

See GetEntryByKey documentation.

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