Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Updating Documents using the Loop function

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):
- BoxNumber;
- StatusNow;

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")
Call View.Refresh
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"
Else
End If      
Call doc.save(True,True)                            
Set doc = view.GetNextDocument(doc)
Loop
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?).
Thank you.
0
CL_Quality_Assurance
Asked:
CL_Quality_Assurance
  • 3
1 Solution
 
HappyFunBallCommented:
I think this line is updating the wrong document

If doc.BoxNumber(0) = docstatus.BoxNumber(0) Then    
docstatus.StatusNow = "Signed Out By User"

It is updating the docstatus document, but I'm assuming it should be updating the doc document, since you call doc.Save right afterwards.

This should do the trick:

If doc.BoxNumber(0) = docstatus.BoxNumber(0) Then    
doc.StatusNow = "Signed Out By User"
0
 
HappyFunBallCommented:
Forgot to answer your other question:  

>> I also attempted to use the 'GetAllDocumentsbyKey', but it failed completely on me (would you know why?).

That's because the GetAllDocumentsByKey method returns a NotesDocumentCollection object rather than a NotesDocument object.
0
 
CL_Quality_AssuranceAuthor Commented:
HappyFunBall - I have incorporated your coding suggestion, and it works!  This is amazing!  (I am an up and coming programmer).

However, after my code above runs, a new screen is kicked off.  Well, I receive the error message of 'Object Variable Not Set'.  If I need assistance, I will let you know.
0
 
HappyFunBallCommented:
I suggest starting the Lotusscript debugger (File > Tools > Debug Lotusscript) and then running the agent again.  See what line is causing the Ojbect Variable Not Set error.  That will help you fix the problem quicker.  And of course, if you have more questions, you can always make a new post here.
0
 
qwaleteeCommented:
Much simpler, one liner....
db.getView("ReqABox").getAllDocumentsByKey(doc.boxNumber).stampAll "StatusNow" , "Checked Out By User"

There is a difficulty with this, which apply whether you use my code, an updated version of your code, or almost anything else...

You are starting off with the "current" document (variable doc in the beginningof your code, where we get doc.Boxnumber(0) to start with).  Inevitably, this document is one of the documents to be modified, which is OK, as it is in the view.  However, I IMAGINE you have the document open, and the user will be making changes and saving it.  That will cause a replication conflict, as the stampAll will operate on one copy of the document (retrieved via the getAllDocumentsByKey) while the UI operates on another copy (the on-screen version).
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now