While developing a Notes application, we discovered a bug with critical consequences under certain circumstances. If you work with documents in a sorted view, it might occur that Notes exchanges an open document with another document. This happens if you switch to read mode, after changing the value of a field which affects the sorting.
A concrete example:
We have two documents in a view. Both documents have a field named "number" which contains a numeric value. The field in the first document has a value of 1, in the second document a value of 2. The documents in the view are sorted by ascending order of the field "number".
You open the first document in edit-mode and change the fieldvalue from 1 to 3.
Then you save the document and switch to read-mode.
Instead of the first document with the value 3, the second document with value 2 is displayed in read-mode.
Why this happens? Because the documents position in the sorted view is modified by the new value, which seems to affect the document that is to be displayed.
We attached a database to this blog post for testing the bug. In the database there are two views (view1, view2). In view1 we have solved the problem already. In view2 you can comprehand the bug with the example.
The following code, we have added to the solution of the problem in view1 in the "Query Mode Change" of the mask of documents:
Dim uiws As New NotesUIWorkspace Dim doc As NotesDocument Dim docReopen As notesDocument Dim newUIDoc As NotesUIDocument Dim item As NotesItem Dim unid As String Dim msgSave As Integer Dim msgReset As Integer If source.EditMode Then If source.ModifiedSinceSaved Then msgSave = Messagebox("Do you want to save your changes?, MB_YESNOCANCEL, "IBM Notes") If msgSave = IDYES Then source.Save Elseif msgSave = IDNO Then msgReset = Messagebox("Do you want to reset the document?" + Chr$(10) + Chr$(10) + _ |If "Yes" the document going to reset to last state before saving.| + Chr$(10) + _ |If "No" the last changes will be displayed unsaved.|, MB_YESNO, "IBM Notes") End If End If If Not msgSave = IDCANCEL Then Set doc = source.Document unid = doc.UniversalID Set item = New NotesItem(doc, "SaveOptions", 0) source.Close If msgReset = IDYES Then Delete doc End If Set docReopen = uiws.CurrentDatabase.Database.GetDocumentByUNID(unid) Set newUIDoc = uiws.EditDocument(False, docReopen) Call uiws.ViewRefresh End If continue = False End If