Hello there. I am requesting assistance with an Agent. 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 needs a box from 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 'In Storage'. When the user presses the button 'Request A Box', this Agent is triggered and runs. Currently, this Agent changes the status of this document from 'In Storage' to 'Signed Out By User'. 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, nothing is happening when the code is running. 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 'In Storage' to 'Signed Out By User.' 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 'Signed Out By User'. Keep repeating until all documents with that identical BoxNumber have the correct status.
Below is my code:
'Status Update for documents
viewkey = doc.BoxNumber(0)
Set view = db.GetView("ReqABox")
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 'Signed Out By User'
Do While Not (doc Is Nothing)
If doc.BoxNumber(0) = docstatus.BoxNumber(0) Then
docstatus.StatusNow = "Signed Out By User"
Set doc = view.GetNextDocument(doc)
Messagebox ("All Instances of this Box # in this Database have been updated to Checked Out")
Can you help me out as to why my Loop is being skipped over? I am still fairly new to this language so I may not be using the correct syntax. I also attempted to use the 'GetAllDocumentsbyKey', but it failed completely on me (would you know why?).