1
votes

I am a beginner in Lotus notes. I have a keyword look-up form and an edit history field. Every change is recorded in the edit history field. The edit history is displayed as shown below:


DATE: 02/10/2016 USER: (name) FROM: keyword::keyword values TO: keyword::keyword values


DATE: 05/29/2016 USER: (name) FROM: keyword::keyword values TO: keyword::keyword values

The append in the edit history is below the previous edit so it is displayed in ascending order. How can I sort the edit history in descending order? Or is it possible to insert new edit history above the previous edit history to make it in descending order? If yes, how can I do this? Thank you in advance for all your help. :)

In my EditHistory multivalued field, I have this code:

@If(@IsDocBeingLoaded & @IsNewDoc; @Return(""); @True);  
@If(!@IsDocBeingSaved; @Return(@Sort(EditHistory;[Descending]));  
@Trim(@Subset(@Sort(EditHistory;[Descending]) ; -100)))

In declarations:

Dim FieldValues() As String 

In my form I have these:

Sub EditHistorylist 
  Dim session As New NotesSession
  Dim workspace As New NotesUIWorkspace
  Dim source As NotesUIDocument
  Dim fieldnum As Integer
  Dim entry As String
  Dim histo As Variant

  Set source = workspace.CurrentDocument 
  For fieldnum = 0 To Ubound(FieldValues)
    If FieldValues(fieldnum,1) <>source.fieldgettext(FieldValues(fieldnum,0)) Then 
      entry = Chr(10) + "DATE:" + Date$+Chr(10)+ "USER:" + session.CommonUserName +_
        Chr(10)+ "FROM:" + FieldValues(fieldnum,0) + "::" + FieldValues(fieldnum,1)+_
        Chr(10)+ "TO:" + FieldValues(fieldnum,0) + "::" + source.fieldgettext(FieldValues(fieldnum,0)) +_
        Chr(10) + Chr(95) + Chr(95) + Chr(95) 
      Call source.FieldAppendText("EditHistory",Chr(10)+entry)
    End If
  Next
End Sub

Document events:

Sub Querysave(Source As Notesuidocument, Continue As Variant)
  If Not Source.IsNewDoc Then
    Call EditHistorylist 
  End If
End Sub

Sub Postmodechange(Source As Notesuidocument) 
  'build array of current values
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Dim doc As NotesDocument
  Dim form As NotesForm
  Dim fieldnum As Integer
  Dim counter As Integer

  Set db = session.CurrentDatabase
  Set doc = Source.Document
  Set form = db.GetForm(doc.Form(0))
  fieldnum = Ubound(form.fields)
  Redim FieldValues(fieldnum,1)
  counter = 0 
  Forall field In form.fields
    FieldValues(counter,0) = field
    FieldValues(counter,1) = source.fieldgettext(field)
    counter = counter + 1
  End Forall
End Sub
2
show us the code, that you use to write the history, then we can show how to modify direction... No code, no help!Torsten Link
In my EditHistory multivalued field, I have this code @If(@IsDocBeingLoaded & @IsNewDoc; @Return(""); @True); @If(!@IsDocBeingSaved; @Return(@Sort(EditHistory;[Descending])); @Trim(@Subset(@Sort(EditHistory;[Descending]) ; -100)))Faith Camille
In declarations: Dim FieldValues() As String In my form I have these: Sub EditHistorylist Dim session As New NotesSession Dim workspace As New NotesUIWorkspace Dim source As NotesUIDocument Dim fieldnum As Integer Dim entry As String Dim histo As Variant Set source = workspace.CurrentDocument For fieldnum = 0 To Ubound(FieldValues)Faith Camille
If FieldValues(fieldnum,1) <>source.fieldgettext(FieldValues(fieldnum,0)) Then entry = Chr(10) + "DATE:" + Date$+Chr(10)+ "USER:" + session.CommonUserName + Chr(10)+ "FROM:" +FieldValues(fieldnum,0) + "::" + FieldValues(fieldnum,1)+Chr(10)+ "TO:" + FieldValues(fieldnum,0) + "::" + source.fieldgettext(FieldValues(fieldnum,0)) + Chr(10) + Chr(95) + Chr(95) + Chr(95) Call source.FieldAppendText("EditHistory",Chr(10)+entry) End If Next End SubFaith Camille
Sub Querysave(Source As Notesuidocument, Continue As Variant) If Not Source.IsNewDoc Then Call EditHistorylist End If End SubFaith Camille

2 Answers

2
votes

To begin with, each line in the history is a string, even if you sort those lines, the result would be sorted in lexicographical order, meaning that 02/10/2016 will still be before 05/29/2016, which would be before 05/29/2015.

Sorting this list after it was completed does not seems the way to go.

is it possible to insert new edit history above the previous edit history to make it in descending order?

Yes of course it is

how can I do this?

It all depend on how the new line is added to the field. With @Formula it would be fairly simple, maybe just history := newLine : history

In LotusScript, you could grab the existing lines with history = document.getItemValue("history"), which would yield an array. You could then use some array-fu to prepend the new line, something along the lines of

redim preserve history(ubound(history)+1)
for i = ubound(history) down to 1
    history(i) = history(i-1)
next
history(0) = newLine
call document.replaceItemValue("history", history)

Now, handling dynamic arrays in LotusScript can be tricky, so arm yourself with patience, and check the help built in Domino Designer.

1
votes

Try this:

Dim newRow(0) As String
newRow(0) = "new history line"
If document.History(0) = "" Then
    document.History=newRow
Else
    document.History =  Arrayappend(newRow, document.history)
End If