Solved

Updating Documents using the Loop function

Posted on 2004-08-12
5
251 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to change default font size and font in Lotus Notes 9 7,295
How do I delete a user in IBM Lotus Notes 2 206
Bulk lotus notes account creation 3 89
Lotus Domino Server 9 4 93
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…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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