查询Lotus Notes中的特定记录

JR *_*ith 1 lotus-notes

我习惯使用关系数据库,您可以在其中定位特定记录.例如,使用下面的伪sql.

SELECT id, name, otherVar FROM students WHERE id=:studentId
Run Code Online (Sandbox Code Playgroud)

但是,我不确定如何在Lotus Notes中使用其平面数据模型进行处理.我一直在谷歌搜索,但不断提出如何更新Lotus Notes本身的点击,而不是Lotus Notes内部的文档.如果拥有一些LN专业知识的人可以指出我正确的方向,那将非常感激.

Nav*_*een 6

使用SQL语句作为类比,假设您有一个students包含列的视图id,name并且otherVar.id应对列进行排序(按升序或降序排列).所以视图看起来像这样

?????????????????????????????????
? id ? name       ? otherVar    ?
?????????????????????????????????
? 1  ? Daniel     ? ----------  ?
? 2  ? Joseph     ? ----------  ?
? 3  ? Michelle   ? ----------  ?
?????????????????????????????????
Run Code Online (Sandbox Code Playgroud)

要查找此视图,您可以在LotusScript中编写类似的内容:

Dim session As New NotesSession 'Get current session
Dim currentDB As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim studentId As String

studentId = "<STUDENT_ID>" 'The student ID that needs to be searched
Set currentDB = session.CurrentDatabase 'Get current database
Set view = currentDB.GetView("students") 'Get the view
Set doc = view.GetDocumentByKey(studentId, True) 'Look up the view with student ID to get the student document
Run Code Online (Sandbox Code Playgroud)

进行简单的Google搜索以NotesView获取更多信息.在公式语言中,您可以将其编写为:

@DbLookup("Notes":"NoCache"; ""; "students"; "<STUDENT_ID>"; "<FIELD TO BE RETRIEVED>"; [FailSilent]);
Run Code Online (Sandbox Code Playgroud)

但是,如果你想进行复杂的计算,公式就不像LotusScript那么灵活.

  • 最好将它称为NoteID,而不是Notes ID - 因为后者很容易与Notes ID文件混淆,后者也是一个完全不同的概念.NoteID不是稳定值.你永远不能确定它匹配任何东西.它甚至不能保证在同一数据库的两个不同副本中匹配同一文档. (3认同)
  • @JRSmith:`getDocumentByID`函数通过Notes ID获取文档.Lotus Notes中还有一个名为Universal ID的东西,概念本身就是一个单独的主题,所以我不会在这里讨论.`getDocumentByID`函数将根据创建文档时由Lotus Notes生成的Notes ID获取文档.你确定`studentId`与文档的Notes ID相同吗?如果是,那么它可以工作,如果没有,那么你必须通过`NotesView`. (2认同)
  • 此外,重要的是要指出,如果studentId匹配"students"视图中第一个已排序列的值,则GetDocumentByKey仅适用于此情况.未能在列上设置sort属性是导致混淆的常见原因. (2认同)