【问题标题】:Lotus notes : how to sort a multi valued field in descending orderLotus Notes:如何按降序对多值字段进行排序
【发布时间】:2016-09-30 02:05:44
【问题描述】:

我是 Lotus Notes 的初学者。我有一个关键字查找表和一个编辑历史字段。每个更改都记录在编辑历史字段中。编辑历史显示如下:


日期:2016 年 2 月 10 日 用户名) FROM: 关键字::关键字值 TO:关键字::关键字值


日期:2016 年 5 月 29 日 用户名) FROM: 关键字::关键字值 TO:关键字::关键字值

编辑历史记录中的追加位于上一次编辑的下方,因此以升序显示。如何按降序对编辑历史进行排序?或者是否可以在先前的编辑历史之上插入新的编辑历史以使其按降序排列?如果是,我该怎么做?预先感谢您的所有帮助。 :)

在我的 EditHistory 多值字段中,我有以下代码:

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

在声明中:

Dim FieldValues() As String 

在我的表单中,我有这些:

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

文档事件:

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

【问题讨论】:

  • 给我们看看你用来写历史的代码,然后我们可以展示如何修改方向......没有代码,没有帮助!
  • 在我的 EditHistory 多值字段中,我有这个代码 @If(@IsDocBeingLoaded & @IsNewDoc; @Return(""); @True); @If(!@IsDocBeingSaved; @Return(@Sort(EditHistory;[Descending])); @Trim(@Subset(@Sort(EditHistory;[Descending]) ; -100)))
  • 在声明中: Dim FieldValues() As String 在我的表单中我有这些: 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) 调用 source.FieldAppendText("EditHistory",Chr (10)+entry) End If Next End Sub
  • Sub Querysave(Source As Notesuidocument, Continue As Variant) If Not Source.IsNewDoc Then Call EditHistorylist End If End Sub

标签: lotus-notes lotusscript lotus lotus-formula


【解决方案1】:

首先,历史记录中的每一行都是一个字符串,即使您对这些行进行排序,结果也会按字典顺序排序,这意味着 02/10/2016 仍将在 05/29/2016 之前,即将在 2015 年 5 月 29 日之前。

在完成后对列表进行排序似乎不是可行的方法。

是否可以在之前的编辑历史之上插入新的编辑历史以使其按降序排列?

是的,当然是

我该怎么做?

这完全取决于如何将新行添加到字段中。使用@Formula 会相当简单,也许只是 历史 := newLine : 历史

在 LotusScript 中,您可以使用 history = document.getItemValue("history") 获取现有行,这将产生一个数组。然后,您可以使用一些 array-fu 来添加新行,类似于

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)

现在,在 LotusScript 中处理动态数组可能很棘手,所以请耐心等待,并查看 Domino Designer 中内置的帮助。

【讨论】:

  • 我收到错误 Unexpected down;预期:操作员; TO in the line For i = Ubound(FieldValues) down to 1 我可以做些什么来解决这个问题?谢谢。
  • RTFM 了解确切的语法 ;-)
【解决方案2】:

试试这个:

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

【讨论】:

    猜你喜欢
    • 2017-06-10
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2011-01-09
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 2021-07-26
    相关资源
    最近更新 更多