如何过滤 selection 文档以防止用户 select 基于字段 "status" 的不同文档

How to filter selection document to prevent user from select different document based on field "status"

在此之前,我问了这个问题,@Torsten Link 建议我过滤文档以防止用户访问 select 不同的文档。基本上我有视图,在这个视图中我有按故障状态排序的文档列表,我将其设置为 PFStatus。所以我有三个状态,即 ObsoleteSpoiltNot Found。所以我想过滤,让用户只能选择这三种状态中的一种,不能混在一起。

所以我尝试使用以下代码进行过滤,但没有任何反应。

Set doc = dc.GetFirstDocument()
    If (doc.PFStatus(0) = "Obsolete" And doc.PFStatus(0) = "Spoilt" And doc.PFStatus(0) = "Not Found") Then
        Messagebox"Please choose either one Write Off selection!"
        Exit Sub
    Elseif (doc.PFStatus(0) = "Obsolete" And doc.PFStatus(0) = "Spoilt") Then
        Msgbox"Please choose only one Write Off selection!"
        Exit Sub
    Elseif (doc.PFStatus(0) = "Obsolete" And doc.PFStatus(0) = "Not Found") Then
        Msgbox"Please choose only one Write Off selection!"
        Exit Sub
    Elseif (doc.PFStatus(0) = "Spoilt" And doc.PFStatus(0) = "Not Found") Then
        Msgbox"Please choose only one Write Off selection!"
        Exit Sub
    Else
        'Some code...
    End If

那么如何过滤 selection 文档?我把代码放错了吗?我真的很感激任何帮助。谢谢你。 :)

更新问题

下面是我的视图名称 "WriteOff"。我有一个创建新批次的按钮。所以我想尝试防止用户创建一个混合了故障状态的批次。

PFStatus 是 multi-value 字段吗?如果不是,则它永远不会有超过 1 个值(除非您以编程方式设置多个值)。还是复选框字段?

我认为如果您只是禁止在视图中从多个类别中选择文档,那将是最好的。参见 https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/basic/H_ONSELECT_EVENT.html


恕我直言,用户永远不应直接输入状态字段。您应该有一些按钮可以引导用户执行某些功能并同时更改状态。

我创建了一个关于如何执行此操作的示例

最好不要把你的代码放在按钮里,而是创建一个代理来把你的代码放进去。这样,你在调试代码时不需要刷新你的视图。

将 'Agent list selection' 设置为触发器和目标 = None。

使用以下公式在视图中创建一个按钮(将 'batch process' 替换为您的代理名称):

@Command([ToolsRunMacro];"(batch process)")

这是一个代理代码示例,说明如何检查所选文档中的 pfstatus 是否相同。

Option Public
Option Declare

Sub Initialize
Dim col As NotesDocumentCollection
Dim doc As NotesDocument
Dim vwUI As NotesUIView
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim dbcurrent As NotesDatabase
Set dbCurrent = session.currentdatabase

'Use vwui.documents to keep documents selected if the agent runs. 
'Like this, a user can deselect a faulty document.
'Don't forget to deselect all docs at the end of your code  
Set vwui = ws.Currentview
Set col = vwui.Documents

'If a user did not 'select' a document (eg V marker before the docline), but merely positioned on a document,
'you need to create a single doc collection based on the caretnoteid (= id of selected document)
If col.count = 0 And vwui.caretnoteid <> "" Then
    Set doc = dbCurrent.Getdocumentbyid(vwui.caretnoteid)
    Set col = dbCurrent.createdocumentcollection()
    Call col.Adddocument(doc)
End If

'Get status from first document to get status to compare against
Dim statusRef As String
Set doc = col.getfirstdocument
If doc Is Nothing Then Exit Sub 'avoid error when no doc is selected
statusRef = doc.pfStatus(0)

'loop other selected documents to compare status
Set doc = col.getNextDocument(doc)
While Not doc Is Nothing
    If doc.pfStatus(0) <> statusRef Then
        'A document with another status is selected, so do not continue
        Msgbox"Please choose only one Write Off selection!"
        Exit sub
    End If
    Set doc = col.getNextDocument(doc)
Wend

'If code gets here, you can loop all documents again to do you batch processing
'Reset doc to first doc in selected collection
Set doc = col.getfirstdocument()
While Not doc Is Nothing
'... some code to run on current doc in the loop ...
    Set doc = col.getNextDocument(doc)
Wend


'Deselect documents at the end of your code
Call vwui.Deselectall()
End Sub