Manage Learn to apply best practices and optimize your operations.

Check For Duplicate Values

This script checks for duplicate values in a database and based on certain
field values will not allow the form to be saved. In this example we are
looking to see if a employee already exists in the database.
Sub Querysave(Source As Notesuidocument, Continue As Variant)
Dim session As New NotesSession
Dim db As Notesdatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim doc2 As NotesDocument
Dim key As String, empName As Variant, displayName As String
Dim ID1 As String, ID2 As String

Set db = session.Currentdatabase
Set doc = source.Document
Const macro1$ = "@Name([CN]; Emp_Name)"

empName = Evaluate(macro1$, doc)

key$ = Ucase( empName(0) )
'ViewName is a (hidden) view sorted by (UpperCase) Emp_Name
'GetDocumentByKey is case sensitive
Set view = db.GetView( "EmpNameLookUp" )
Set doc2 = view.GetDocumentByKey( key$ )
'If doc can not be found Key does not exist
If Not (doc2 Is Nothing) Then
ID1$ = doc.UniversalID
ID2$ = doc2.UniversalID
'You have to check if the id of the doc found is not current doc
'In case you save the doc more than once
If Ucase( doc2.Emp_Name(0) ) = key$ And ID1$ <> ID2$ Then
displayName$ = Strconv(key$, SC_ProperCase)
Messagebox "User: " & displayName$ & " already
exist"
Call source.FieldClear( "Emp_Name" )
continue = False
Exit Sub
End If
End If

key$ = doc.Emp_Nr(0)
'ViewName is a (hidden) view sorted by Emp_Nr
'GetDocumentByKey is case sensitive
Set view = db.GetView( "EmpNoLookUp" )
Set doc2 = view.GetDocumentByKey( key$ )
'If doc can not be found Key does not exist
If Not (doc2 Is Nothing) Then
ID1$ = doc.UniversalID
ID2$ = doc2.UniversalID
'You have to check if the id of the doc found is not current doc
'In case you save the doc more than once
If doc2.Emp_Nr(0) = key$ And ID1$ <> ID2$ Then
Messagebox "Employee Number: " & key$ & " already exist"
Call source.FieldClear( "Emp_Nr" )
continue = False
Exit Sub
End If
End If
doc.SaveOptions = 0
Call source.Close
End Sub

Dig Deeper on Domino Resources - Part 3

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close