如何过滤选择文档以防止用户基于“状态”字段选择其他文档

时间:2019-07-17 04:33:14

标签: lotus-notes lotusscript

在此之前,我会问这个问题,@ Torsten Link建议我过滤文档以防止用户选择其他文档。基本上,我有一个视图,在这个视图中,我具有按故障状态排序的文档列表,我将其设置为PFStatus。因此,我有三个状态:已过时已损坏未找到。因此,我想进行过滤,以便用户只能选择这三种状态,而不能混淆。

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

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

那么如何过滤选择的文档?我是否以错误的方式放置了代码?任何帮助我都非常感谢。谢谢。 :)

更新问题

下面是我的视图名称“ WriteOff”。我有一个按钮来创建新批次。因此,我想尝试防止用户创建状态错误的批次。

pic

2 个答案:

答案 0 :(得分:1)

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

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


恕我直言,状态字段绝对不能由用户直接输入。您应该具有指导用户执行某些功能并同时更改状态的按钮。

答案 1 :(得分:1)

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

最好不要将代码放入按钮中,而是创建一个代理以将代码放入其中。这样,在调试代码时无需刷新视图。

将“代理列表选择”设置为触发器,并且Target = None。

enter image description here

使用以下公式在视图中创建一个按钮(用代理名称替换“批处理”):

@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