文档未循环查找 "Active" 状态的所有文档

Document did not loop to find all document for "Active" status

我有一个名为 PC Inspection 的流程。抄送检验时,每次检验批号都会改变。并且有称为 EmpPCSpec 的 pc 检查表。它将从计算机文档中复制数据。

我可以创建批次,但它只为所选的一个文档创建。

下面是设置新批次和创建pc检验表的lotusscript代码。

Sub Click(Source As Button)
  Dim session As New NotesSession
  Dim workspace As New NotesUIWorkspace
  Dim db As NotesDatabase
  Dim collection As NotesDocumentCollection

  Set db = session.CurrentDatabase
  Set collection = db.UnprocessedDocuments

  Dim ws As New NotesUIWorkspace
  Dim uiview As NotesUIView
  Set uiview = ws.CurrentView

  answer% = Messagebox("Do you want to set batch number?", 4,"Batch Number")
  If answer% = 6 Then

    InputBatchNo = Inputbox("Please insert the Batch Number.  eg : 2014A")

    If Not InputBatchNo="" Then

      For ii = 1 To collection.count
        Set doc = collection.GetNthDocument(ii)

        currbatchno = doc.PBatchNo(0)
    '--------------------------------------
    Gosub SetNewBatchNo
    '---------------------------------------
    doc.PBatchNo =newbatchno

    '------------ set new acceptance form ---------------------------
    If doc.PStatus(0) = "Active" Then
    Set comdoc = New NotesDocument (db)
    comdoc.Form = "EmpPCSpec"

    comdoc.ATagNo = doc.PTagNo(0)
    comdoc.AYear= Left(InputBatchNo,4)
    comdoc.ADept= doc.PDept(0)
    comdoc.AUserName= doc.PUserName(0)
    comdoc.AUserID= doc.PUserID(0)
    comdoc.AUserGroup= doc.PUserGroup(0)
    comdoc.ALocation= doc.PLocation(0)
    comdoc.AStatus= doc.PStatus(0)
    comdoc.ABatchNo=doc.PBatchNo(0)

    comdoc.AProcessor= doc.PProcessor(0)
    comdoc.ASerialNo= doc.PSerialNo(0)
    comdoc.ABrand= doc.PBrand(0)
    comdoc.AModel= doc.PModel(0)
    comdoc.AType= doc.PType(0)
    comdoc.ADisplayUnit= doc.PDisplayUnit(0)
    comdoc.ADisplaySize= doc.PDisplaySize(0)
    comdoc.ADisplayBrand= doc.PDisplayBrand(0)
    comdoc.ARam= doc.PRam(0)
    comdoc.AHDD= doc.PHDD(0)
    comdoc.AIPAddress= doc.PIPAddress(0)
    comdoc.AOperatingSys= doc.POperatingSys(0)
    comdoc.ACalLicense= doc.PCalLicense(0)

    Call comdoc.ComputeWithForm(False,False)
    Call comdoc.save(True,True)

    '----------------------------------------------------------------

    Call doc.ComputeWithForm(False,False)
    Call doc.save(True,True)
      End If
    Next

    Messagebox("Process completed." & Chr(13) & "Press 'F9' to refresh the view.")

  Else
    Messagebox("Please insert Batch Number.")
  End If

End If

Exit Sub

SetNewBatchNo:

    currbatchno1 = Strtoken(currbatchno, "-", 1)

    If InputBatchNo = currbatchno1 Then
        seqno = Strtoken(currbatchno, "-", 2)
        newseqno = Val(seqno) +1
        newseqno1 = Format(newseqno, "0000")

        newbatchno = InputBatchNo + "-" + newseqno1
    Else
        newbatchno = InputBatchNo + "-" + "0001"
    End If

    Return

End Sub

如果状态为 "Active",我如何通过循环获取所有文档?任何帮助将不胜感激。谢谢!

此代码存在许多问题:应避免使用 getNthDocument,因为它是性能杀手和不良做法 - 至少对于较大的集合而言,因为代码会在每次使用 getNthDocument 时重新计算文档的位置.请改用 getFirstDocument 和 getNextDocument。带有goto的逻辑也是如此。这很难阅读、理解,尤其是维护。我建议您创建这样的逻辑:

Set collection = db.UnprocessedDocuments
set doc = collection.getFirstDocument()
while not doc is nothing
    if doc.status(0) = "Active" then

        <your logic goes here>

    end if

//next doc for processing
set doc=collection.getnextdocument(doc)
wend

除了上述问题外,我认为您的代码存在的问题是您没有在所有选定的文档中建立任何类型的循环 - getNthDocument() 仅执行一次,因此仅涉及一个文档。但是正如我已经说过的,由于使用了 goto,很难阅读和理解代码在运行时跳转到的时间和位置。