Solved

Updating Documents using the Loop function

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now