How to fix: Unexpected duplicate entries found in events4.nsf


Some times after you upgrade the Domino server, you might occasionally see this error message in the console:

Diagnostics on view ($Messages) of database events4.nsf was aborted: Unexpected duplicate entries found.

Which basically indicates that there are some Event Messages sharing the same Event ID.

This can happen because some Event Messages might have been updated in the events4 template shipped with the new version, and when these updated messages are copied to the old database, the old message may get left over for one reason or another. In one case I found that the Event ID had different capitalization in the duplicate documents.

Regardless of the reason, you want to clean the duplicates up. The first thing to try is to let the Event task take care of it by issuing the command:

tell event clean ($Messages)

If the error message you’re receiving is about an issue in a different view, you can change the view name in this command. Basically the syntax is:

tell event clean <view name>

If this does not solve your issue, you can write a simple Agent that scans the affected view directly. To do so:

  1. Open the events4.nsf database in the Domino Designer.
  2. Create a new Agent (Lotus Script). Name it: Detect $Messages duplicates
  3. Use the following code, which checks for duplicates in the ($Messages) view.
  4. Change the Agent Trigger to “Actions Menu”, and the Target to “None”. Then save it.
  5. Run the Agent from the Notes Client.

Here’s the code:

Sub Initialize
 Dim s As New NotesSession
 Dim db As NotesDatabase
 Dim v As NotesView
 Dim doc As NotesDocument

 Set db = s.CurrentDatabase
 Set v = db.GetView("($Messages)")
 Call v.Refresh()
 v.AutoUpdate = False

 Set doc = v.GetFirstDocument()

 Dim dc As NotesDocumentCollection
 Dim ID As String

 Do Until doc Is Nothing
   ID = doc.GetItemValue("Value")(0)
   Set dc = v.GetAllDocumentsByKey(ID, True)
   If dc.Count > 1 Then
     Print "Message with ID: " & ID & " is duplicated."
     MsgBox "Message with ID: " & ID & " is duplicated. No more processing will be done. Additioanl duplicates may exist."
     Exit sub
   End If

   Set doc = v.GetNextDocument(doc)

 MsgBox "No duplicates found."
 Print "No duplicates found."
End Sub

When run, this Agent will show a message box with the Event ID of the first duplicate Event Message it encounters.

To resolve the duplication, in the Notes Client, while the events4 database is open, open the View menu, hold down Ctrl+Shift, and click Go To…

Select the ($Messages) view from the list to open this view, and then search for the Event ID.

It’s up to you to decide how to resolve the duplication. Basically you can just review the documents, then decide to keep one of them and delete the other. If you are not sure, check the creation & modification times of the documents. You can also check the same ID in the template events4.ntf.. In this case, you might as well just delete all of the Event Messages and copy them from the Template. However, I have not tested whether this could cause any undesired side effects, so you may want to test with it after taking a backup.