LotusScript - 任何人都可以修复我的功能吗?

时间:2011-11-24 14:52:38

标签: function lotus-notes lotusscript

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

但搜索没有提起 - 我可以继续将相同的约会输入数据库。

如果有人能够发现我的代码无效的原因,我会很感激帮助。

由于

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

3 个答案:

答案 0 :(得分:3)

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)

答案 1 :(得分:2)

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

所以我的猜测是你希望代码说出来:

Set entry = selectView.GetEntryByKey(key, True)

而不是:

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

答案 2 :(得分:0)

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

请参阅GetEntryByKey文档。