Solved

Code Updating Documents Not Selected for Loop

Posted on 2004-08-18
8
297 Views
Last Modified: 2013-12-18
Hello there.  I am requesting assistance with an Agent.  I received assistance with you guys before on this, now I turn to you again.  HappyFunBall has been involved in my requests so he is familiar with them by now.

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 'Checked Out'.  This field is called 'status'.  There are thousands of documents in our database with BoxNumbers.  

I have an interesting issue now.  The Loop is running and is updating all of the documents that I want, which is great.  However, for some unknown apparent reason, other documents are going through the Loop as well, even though I did not want them to be.  For example, I am requesting Box #12345, and runs the Agent (below).  All instances of this Box (#12345) are updated correctly.  However, there are other (boxes) documents in the database.  Let's say Box #00999 is another (box) document in the database.  When I request Box #12345, Box #00999 status is being updated as well.  I don't want Box #00999 status to be updated. I have noticed that Box #00999 is the first listed in the database and starts with '00'.

The Loop is working, but is picking up other documents.

This time, I put the entire code in to review because the issue may be higher in my code.  Could this issue be caused by the 'GetFirstDocument' command located in my Loop?

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase  
Set db = session.CurrentDatabase
Dim collect As NotesDocumentCollection
Dim doc As NotesDocument
Dim NewDoc As NotesDocument    
Dim uidoc As NotesUIDocument
Dim workspace As New NotesUIWorkspace
Dim answer As Integer
Dim item As NotesItem    
Dim datetime As NotesDateTime
Dim CurrentDate As New NotesDateTime("Today")
Dim viewkey As String
Dim docstatus As NotesDocument
Dim docLoop As NotesDocument
Set collect = db.UnprocessedDocuments

'Check to see if a document was selected
If collect.count = 0 Then
Msgbox "You must first select a document.",48,"Check out a Box"
Exit Sub
End If
      
'Check to see if multiple documents were selected
If collect.count > 1 Then
Msgbox "Please select only one document.",48,"Check out a Box"
Exit Sub
End If
Set doc = Collect.GetFirstDocument    

'Check to see if an Invoice document was selected
If doc.Form(0) <> "RECORD RETENTION INFORMATION" Then
Msgbox "Please select a Document.",48,"Check out a Box"
Exit Sub
End If
      
'Display MessageBox
answer = Msgbox("This button will sign out a Box from storage, do you want to continue?", 36, "Check out a Box")
'Check to see if user pressed the Yes button  
If answer = 6 Then
Else
Exit Sub
End If
      
'Display MessageBox
answer = Msgbox("Is This a Rush Request?", 36, "RUSH REQUEST?")
'Check to see if user pressed the Yes button  
If answer = 6 Then
Doc.Rush = "Iron Mountain - PLEASE RUSH Box Request"
Else
End If
If answer  <> 6 Then
Doc.Rush = "Iron Mountain Box Request"
Else
End If
      
'Status Update for documents      
viewkey =  doc.BoxNumber(0)  
Set view = db.GetView("ByBoxNum")
Call View.Refresh
Set docstatus = view.GetDocumentByKey(viewkey, True)
Set docLoop = 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 'Checked Out'
Dim UserName4 As New NotesName(session.UserName)          
Do While Not (docLoop Is Nothing)
     If docLoop.BoxNumber(0) = docstatus.BoxNumber(0) Then    
     docLoop.status = "Checked Out"
     docLoop.MemoReq = UserName4.Common      
Else
End If      
Call docLoop.save(True,True)                            
Set docLoop = view.GetNextDocument(docLoop)
Loop
Call View.Refresh
Msgbox "All Accounts associated with this Box Number have been updated to Checked Out.",48,"Check Out Confirmation"
Set view = db.GetView("Mainview")
Call View.Refresh
Set view = db.GetView("Statusview")
Call View.Refresh
      
'Create a New Business Form document
Set uidoc = workspace.ComposeDocument( "", "", "Check out Activity" )
uidoc.AutoReload = False
Set NewDoc = uidoc.Document
Call uidoc.save
Call doc.CopyAllItems(NewDoc,True)
Set  doc.Outdate = CurrentDate
doc.InDate = " "
'Update selected New Business Form document
Call doc.save(True,True)
'Update New New Business Form document
Set NewDoc.REQUEST_DATE = CurrentDate
NewDoc.STATUS = "Checked Out"

Dim UserName3 As New NotesName(session.UserName)          
Doc.MemoReq = UserName3.Common      
Call doc.save(True,True)
Dim mdoc1 As NotesDocument
Set mdoc1 = New NotesDocument( db )
mdoc1.Form = "Memo"
mdoc1.SendTo = "James L Bouse/Travelers"      
'mdoc1.SendTo = "CTCUSTSERV@IRONMOUNTAIN.COM"      
'mdoc1.CopyTo = "NATRET Email"
mdoc1.Subject = Trim$(Doc.Rush(0))
Dim UserName1 As New NotesName(session.UserName)
mdoc1.Body =  UserName1.Abbreviated & " has requested the Box Number of " & Doc.BoxNumber(0) & " from Iron Mountain, storage code of " & Trim$(Doc.Code(0))_
& ". Please send this request to St. Paul Travelers, Hartford, CT - 9CR. " 
Call mdoc1.Send( False )
Call uidoc.Reload      
Call uidoc.save
      
Dim agent As NotesAgent
Forall a In db.Agents
     If a.Name = "Clear the Checker Field" Then
     Set agent  = a
     Call agent.Run
Exit Forall          
End If
End Forall
End Sub

Also, is there a command to update all refresh all views at once and not individually?

Thank you for your assistance.
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
  • 5
  • 2
8 Comments
 
LVL 9

Accepted Solution

by:
HappyFunBall earned 450 total points
ID: 11836083
The collect.GetFirstDocument selects the first document in the document collection.  The document collection contains all the documents selected by the user before he/she pushed the Request a Box button.  And since there's a check in there that only one document exists in the collection, you can be sure the document you're working with (set to the object variable 'doc') is the one document selected by the user.

The problem you're having appears to be coming from that pesky loop area.  I think you need to change the loop section to this:

'Status Update for documents    
Set view = db.GetView("ByBoxNum")
Call View.Refresh
Set docLoop = 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 'Checked Out'
Dim UserName4 As New NotesName(session.UserName)          
Do While Not (docLoop Is Nothing)
     If docLoop.BoxNumber(0) = doc.BoxNumber(0) Then    
     docLoop.status = "Checked Out"
     docLoop.MemoReq = UserName4.Common      
Call docLoop.save(True,True)  
End If    
                       
Set docLoop = view.GetNextDocument(docLoop)
Loop

Also there's no command to refresh all views, but you could write a short loop to do so.  I don't think there's really any need to do that however.  The view should refresh the next time the user opens the view.
0
 

Author Comment

by:CL_Quality_Assurance
ID: 11840441
Thank you HappyFunBall, I will give a try.  I am on the East Coast so sometimes I do not get your replies until the next morning, like this one.

I thought it had something to do with the 'CollectFirstDocument' and my Loop.
0
 

Author Comment

by:CL_Quality_Assurance
ID: 11841592
I ran into my worst friend, the error message of: "Object Variable Not Set.".  It occurred at the point of (where I put 'HERE THIS LINE' below):

'Status Update for documents    
Set view = db.GetView("ByBoxNum")
Call View.Refresh
Set docLoop = 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 'Checked Out'
Dim UserName4 As New NotesName(session.UserName)          
Do While Not (docLoop Is Nothing)
    If docLoop.BoxNumber(0) = doc.BoxNumber(0) Then   (HERE THIS LINE)
     docLoop.status = "Checked Out"
     docLoop.MemoReq = UserName4.Common      
Call docLoop.save(True,True)  
End If    
                       
Set docLoop = view.GetNextDocument(docLoop)
Loop
 
I don't fully understand this error message and why it is occurs when I defined all of my variables.
0
Independent Software Vendors: 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!

 
LVL 9

Assisted Solution

by:HappyFunBall
HappyFunBall earned 450 total points
ID: 11844664
Hmm...when you're debugging this in the script debugger, you can look at the bottom of the screen and see the variables and their values.  It must be either docLoop or doc that is 'not set', so take a look and see which one has no information to the right of the variable name.  It doesn't make sense to me either since docLoop is set to the first document in the view, and the doc variable is set to the selected document earlier.  

Another way to do this is to change the Do Loop to this, and then see what line it stops on.  

Dim sBoxNumber as String
Dim sBoxNumberSel as String
sBoxNumberSel = doc.BoxNumber(0)
Do While Not (docLoop Is Nothing)
    sBoxNumber = docLoop.BoxNumber(0)    
    If sBoxNumber = sBoxNumberSel Then  
     docLoop.status = "Checked Out"
     docLoop.MemoReq = UserName4.Common      
Call docLoop.save(True,True)  
End If    
                       
Set docLoop = view.GetNextDocument(docLoop)
Loop
0
 

Author Comment

by:CL_Quality_Assurance
ID: 11845456
Okay...let me try to explain what is going on.  I am new to this and coding is fun, but it times like these, it is driving me crazy!  But, I am determined to get through this successfully and get a working product (unlike, unfortunately, what is in Production currently).

I ran the Agent.  I attempted to determine, down below, to study the variable results:
These are the variables that do not have values assigned to the right of them:
- NEWDOC
- UIDOC
- ITEM
- DATETIME
- DOCSTATUS

(remember, the times below are EST):
The variable, 'DOC' has all this information on it: "False, 08/19/04, 02:41:13 PM"
The variable, 'docLoop' has all this information on it: "False, 08/19/04, 02:41:13 PM"
When I press the '+' key for these variables, all this information is filled in, information such as code, and the time and date (of today).

2.  I copied your Loop directly into my agent.  When I run the Agent, ALL the documents are updated with 'Checked Out'!.
0
 

Author Comment

by:CL_Quality_Assurance
ID: 11845989
Okay, I am thinking that the culprit is the 'docstatus'.  I commented out "Set docstatus = view.GetDocumentByKey(viewkey,True), therefore, my Loop is looking for docstatus and there is none. I commented out the docstatus so I could have the Loop not grab other documents.

'viewkey =  doc.BoxNumber(0)  
Set view = db.GetView("ByBoxNum")
Call View.Refresh
'Set docstatus = view.GetDocumentByKey(viewkey, True)
Set docLoop = 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 'Checked Out'
Dim UserName4 As New NotesName(session.UserName)          
Do While Not (docLoop Is Nothing)
If docLoop.BoxNumber(0) = docstatus.BoxNumber(0) Then     (STOPS HERE)

docLoop.status = "Checked Out"
docLoop.MemoReq = UserName4.Common      
Else
Call docLoop.save(True,True)                            
End If      
Set docLoop = view.GetNextDocument(docLoop)
Loop
Call View.Refresh
0
 
LVL 31

Assisted Solution

by:qwaletee
qwaletee earned 50 total points
ID: 11855019
viewkey =  doc.BoxNumber(0)  
Set view = db.GetView("ByBoxNum")
Call View.Refresh
Set docstatus = view.GetDocumentByKey(viewkey, True)
.... If docLoop.BoxNumber(0) = docstatus.BoxNumber(0) Then    


This is redundant.  You get the viewkey, use it to get the first matching doc, and use that doc's same key to match.  Just keep using viewKey!

Plus, this is an inefficient loop.  It SHOULD work, but is badly coded.  You should start by setting the first doc based on getDocumentByKey ( viewKey , true ), and you should terminate theloop as soon as one os found that does notmatch.
0
 

Author Comment

by:CL_Quality_Assurance
ID: 11884810
Can you assist me in writing a better loop?  I am new to this coding and always had trouble with a loop.  I am open to new ways to improve my coding.

I understand what I am trying to accomplish, but the actual code writing is hard for me.

Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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
Email relaying to outside address 4 178
Querying received e-mails from an agent 7 209
Lotus notes VB code 4 212
NT Kernel & System Process CPU Usage Maxin out 8 61
  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…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

733 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