The following article demonstrates how to manipulate the order of documents in a view (both documents and responses) using a date field (or in the view, a timestamp-ordered column) and the NoteViewNavigator class in LotusScript.
Now that the date field is on each of the forms insert a column at the beginning of the view. Mark the column as hidden. Chose reorderStamp as the field value for the column. Sort the column in ascending order.
In order to perform this move each of the action buttons will use LotusScript to swap the values of the reorderStamp in a selected view entry with one (top or bottom) of its siblings. If the entry is a response document it will move it above or below one of it's siblings. If the view entry is a document (main) then it will move it along with it's children (responses) above or below one of it's siblings.
First, declare some of the Notes objects that will be used:
Dim view As NotesView
Dim nav As NotesViewNavigator
Dim entry As NotesViewEntry
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim selected As NotesDocument
Dim reorderStampTime As NotesDateTime
Next, set the view's autoupdate property to false. The view should not update until the action completes.
Set view = ws.CurrentView.View
view.AutoUpdate=False
Create the ViewNavigator from the view:
Set nav = view.CreateViewNav
The actions in this example are set up to only move one document at a time (parents do move with their children though). Check to make sure that the view is not empty, that only one view entry is select and that the view entry selected is not already at the top of the view:
Set dc = db.UnprocessedDocuments
'No documents in the view so end it here
If (dc.Count() = 0 ) Then
Msgbox "Nothing in the view", 48, "View Empty"
Exit Sub
'More than one document is selected so end it here
Elseif (dc.Count() > 1) Then
Msgbox "You can only move one item at a time!",48, "New Number Warning"
Exit Sub
End If
Set selected = dc.GetFirstDocument()
'Parent document: check for it being the first entry
Set entry = nav.GetFirst
If (entry.UniversalID = selected.UniversalID ) Then
Msgbox "This item is already at the top." , 48, "Top Level Item"
Exit Sub
End If
'Response documents: check to see if the selected doc is the first Child
Do While Not(entry Is Nothing)
If (selected.UniversalID = entry.UniversalID ) Then
Exit Do
End If
Set entry = nav.GetNext(entry)
Loop
If (entry Is Nothing) Then
Exit Sub
End If
'Establish ENTRY as the previous sibling
Set entry = nav.GetPrevSibling(entry)
If (entry Is Nothing) Then
Msgbox "This item is already at the top of its level." , 48, "Top Level Item"
Exit Sub
End If
With the selected entry verified now it is time to swap the timestamp values. Retrieve the reorderStamp value from the selected view entry and save it to the reorderStampTime object. Then swap the selected view entry with it's previous sibling's and save both backend documents.
Set reorderStampTime = s.CreateDateTime(entry.Document.getITemValue("reorderStamp")(0))
Dim entryDoc As NotesDocument
Set entryDoc = entry.Document
Call entryDoc.CopyItem(selected.GetFirstItem("reorderStamp"), "reorderStamp")
Call entryDoc.Save(False, False)
Set selected.reorderStamp = reorderStampTime
Call selected.Save(False,False)
Finally, refresh the view: