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

SearchWindowsServer

Search400

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury

SearchDataCenter

SearchContentManagement

Close