获取第一个在Lotus中没有返回任何内容

时间:2014-05-22 20:52:40

标签: lotus-notes lotusscript

当我试图在当前视图中访问所选文档的字段时,我什么都没得到。 我的代码:

Sub Click(Source As Button)
  Dim ws As New NotesUIWorkspace
  Dim uiview As NotesUIView 
  Dim dc As NotesDocumentCollection 
  Dim doc As NotesDocument 
  Dim receive As String 
  Set uiview=ws.CurrentView
  Set dc=uiview.Documents
  Set doc=dc.GetFirstDocument
  If doc Is Not Nothing Then
    receive=doc.GetItemValue("Field name")
  End If
End Sub

它永远不会输入if因为doc总是什么都没有...当我删除if时,当getitemvalue尝试获取某些内容时会出现错误,但它不能

2 个答案:

答案 0 :(得分:2)

dc.GetFirstDocument不返回任何内容,因为该集合为空。如果您没有选中带有复选标记的文档,就会发生这种情况。 uiview.Documents仅提供所选文档,而突出显示的文档。

如果您只想查看突出显示的文档(框架中的文档) enter image description here 那么这将有效:

Sub Click(Source As Button)
    Dim session As New NotesSession
    Dim doc As NotesDocument
    Set doc = session.DocumentContext
    If Not doc Is Nothing Then
        receive=doc.GetItemValue("FieldName")(0)
        Print receive
    End If
End Sub

session.DocumentContext会在视图中返回突出显示的文档。

如果您想要查看所有选定的文件

enter image description here您可以使用稍加修改的代码

Sub Click(Source As Button)
    Dim ws As New NotesUIWorkspace
    Dim uiview As NotesUIView
    Dim dc As NotesDocumentCollection
    Dim doc As NotesDocument
    Set uiview = ws.CurrentView
    Set dc = uiview.Documents
    Set doc = dc.GetFirstDocument
    While Not (doc Is Nothing)
        Print doc.GetItemValue ("FieldName")(0)
        Set doc = dc.GetNextDocument (doc)
    Wend
End Sub

答案 1 :(得分:0)

试试这个(密钥为'UnprocessedDocuments'):

Sub Click (Source as Button)
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim DocColl As NotesDocumentCollection
    Dim doc As NotesDocument
    Set db = s.CurrentDatabase
    Set DocColl = db.UnprocessedDocuments
    Set doc = DocColl.GetFirstDocument()
    if not (doc is Nothing) then
        Print doc.GetItemvalue("FieldName")(0)
    End if
End Sub

当前选定的(突出显示或勾选的)文档将填充文档集。

干杯。