Updating document using the Loop Function - Part II
Posted on 2004-08-13
Hello there. I am requesting assistance with an Agent.
This is same concept as the Question titled: "Updating documents using the Loop Function" in which I requested help and received a great answer yesterday. Now, using the same concept with another agent, I am hitting an error message, as described below.
I am trying to perform a Loop where multiple documents can be updated at one time.
The business side of this application is the tracking of storage boxes in our warehouse. These boxes contain financial, payment, legal documents. When a user RETURNS a box to the warehouse, they select the document with that BoxNumber in the database. Each document has a BoxNumber, and many documents can share the same BoxNumber. The current status of this document is 'Signed Out'. When the user presses the button 'Return A Box', this Agent is triggered and runs. Currently, this Agent changes the status of this document from 'Signed Out' to 'In Storage'. This field is called 'StatusNow'.
This same BoxNumber can appear on other documents. My issue is that other documents that share this BoxNumber are not being updated with the current status. Currently, an error message is occurring of: 'Notes error: Entry not found in index (and view name)'.
I have declared all of my variables already.
This agent runs 'On event'.
The fields on my form are (used for this Agent are):
What I am attempting to accomplish:
When the Agent runs, change the first document field of 'StatusNow' from 'Signed Out' to to 'In Storage.' Go to the next document. If the BoxNumber of the next document is identical as the BoxNumber of the first document, change the 'StatusNow' field of this next document to 'In Storage'. Keep repeating until all documents with that identical BoxNumber have the correct status.
Below is my code:
viewkey = doc.BoxNumber(0)
Set view = db.GetView("ByBoxNum1")
Set docstatus = view.GetDocumentByKey(viewkey, True)
Set doc = view.GetFirstDocument()
'Obtain Box Number of the document updated - if any other documents in the database have this same Box Number, change their status to 'In Storage'
Do While Not (doc Is Nothing)
If doc.BoxNumber(0) = docstatus.BoxNumber(0) Then
doc.statusnow = "Signed In"
Set doc = view.GetNextDocument(doc)
Msgbox "All Accounts associated with this Box Number have been updated to Checked In.",48,"Check In Confirmation"
What I do know:
I have run this with the Debug LotusScript on. I go through successfully the first time and then hit the 'Loop', and return successfully to the Do While statement. I make it successfully to 'Loop' again, but then I fail. The error is: 'Notes error: Entry not found in index (and view name)'. I am confused by the fact that the first document that went through, it's status was changed successfully. Any next document that tries to go through fails. What does the Loop not keep going?
Can you help me out as to why my Loop is failing after I set up the same logic yesterday in another agent?