LotusScript - Кто-нибудь может исправить мою функцию? - PullRequest
0 голосов
/ 24 ноября 2011

Я пытаюсь написать функцию проверки, которая проверяет, существует ли добавляемая запись в наборе данных.

Но поиск не находит ее - я могу просто продолжать вводить ту же самуюназначение в базу данных.

Если кто-нибудь может определить, почему мой код не работает, я был бы признателен за помощь.

Спасибо

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 ]

3 голосов
/ 24 ноября 2011

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)
2 голосов
/ 25 ноября 2011

Вы используете пять строк кода, чтобы заполнить локальный вариантный массив с именем key, но на самом деле вы не используете этот массив для вызова GetEntryByKey.

Итак, я предполагаю, что вы хотите, чтобы код сказал это:

Set entry = selectView.GetEntryByKey(key, True)

вместо этого:

Set entry = selectView.GetEntryByKey(thisDoc.key, True)
0 голосов
/ 25 ноября 2011

Сортируется ли представление allLocationRecordsByName для каждого столбца, включенного в ключ поиска?

См. Документацию GetEntryByKey .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...