Manage Learn to apply best practices and optimize your operations.

Prevent Duplicate Documents On Save

This is a handy way I use to prevent users from saving duplicate documents. A
document is defined by the document key, which is determined by your

1. Create a view of all documents, sorted by the key field or value of the key.
Limit the
view selection formula to those forms you wish to prevent duplicates for.
2. Create a field on the each form which evaluates to the key value. It should
be a
computed field.
3. Place the code for the Ok2Save function below in the Globals section of your
This allows the function to be called anywhere within your form.
4. Place the following code fragment into the QuerySave event on each form
which contains
the key field: Continue = Ok2Save( source ).
5. In any buttons on your form which save the document, call Ok2Save(
NotesUIDocument ) to
determine if you can save the document.

This will prevent documents from being saved if a document with the same key
exists in the
database. Enjoy!

Function Ok2Save( source As NotesUIDocument ) As Variant
Dim view As NotesView
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim s As New NotesSession
Dim key As String
Dim key2 As String
Dim item As NotesItem

' get the current database and view
Set db = s.CurrentDatabase
Set view = db.GetView("(all)") ' this is the view created in step 1 above

' refresh document for validation formulas and get key for this document
Call source.Refresh
key = source.fieldgettext("key")

' check to see if the document key already exists....
Set doc = view.getdocumentbykey( key )

If doc Is Nothing Then
' first time saved
Ok2Save = True
Exit Function
Set item = doc.GetFirstItem("key")
key2 = item.values(0)
If key2 = key Then
' key matched...possible duplicate"
' subsequent saves
If doc.UniversalID = source.document.UniversalID Then
'saving same document
'unid matched, same doc, saving..."
Ok2Save = True
Exit Function
' duplicate document
' unid is different with same key...duplicate document"
Messagebox "This would create a duplicate document. Save
Ok2Save = False
End If
' keys dont match not the same document
'keys dont match...saving"
Ok2Save = True
End If
End If
End Function

Dig Deeper on Domino Resources



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ 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