Solved

Code Updating Documents Not Selected for Loop

Posted on 2004-08-18
8
288 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
  • 5
  • 2
8 Comments
 
LVL 9

Accepted Solution

by:
HappyFunBall earned 450 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 9

Assisted Solution

by:HappyFunBall
HappyFunBall earned 450 total points
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:CL_Quality_Assurance
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

17 Experts available now in Live!

Get 1:1 Help Now