Solved

Updating Documents using the Loop function

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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