Solved

Updating Documents using the Loop function

Posted on 2004-08-12
5
253 Views
Last Modified: 2013-12-18
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
Comment
Question by:CL_Quality_Assurance
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 9

Accepted Solution

by:
HappyFunBall earned 500 total points
ID: 11786605
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
 
LVL 9

Expert Comment

by:HappyFunBall
ID: 11786616
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
 

Author Comment

by:CL_Quality_Assurance
ID: 11786941
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
 
LVL 9

Expert Comment

by:HappyFunBall
ID: 11787094
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
 
LVL 31

Expert Comment

by:qwaletee
ID: 11788059
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question