Reputation: 195
I have a process called PC Inspection. When copy inspection, batch no will be change every time inspection is done. And there is pc inspection form called EmpPCSpec. It will copy data from computer document.
I can create batch but it only created for one document selected only.
Below are the lotusscript code to set new batch and create pc inspection form.
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
How can I get all document where if status is "Active" by looping it? Any help will be appreciated. Thanks!
Upvotes: 0
Views: 58
Reputation: 1399
There are a number of issues with this code: using getNthDocument should be avoided as it is a performance killer and bad practice - at least for larger collections as the code will recalculate the position of the document on every use of getNthDocument. Use getFirstDocument and getNextDocument instead. The same is true for the logic with goto. This is difficult to read, understand and especially to maintain. I suggest you create a logic like this:
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
Besides the above mentioned issues I think the issue with your code is that you did not establish any sort of looping through all selected documents - getNthDocument() is executed only once, therefore only one document is being touched. But as I already said it is dificult to read and understand when and where the code jumps to during runtime due to the use of goto.
Upvotes: 4