Solved

Agent that will update all docs in a database

Posted on 2000-05-11
2
213 Views
Last Modified: 2013-12-18
I'm using the code below to connect to an AS/400 thru an odbc connection. I put this code into an agent and it works fine if I have the document open in edit mode. Is it possible to run the agent from a view and have it update all the documents in the database? When I select a document in a view and run the agent I get an error message "Object variable not set" Looking at this in the lotusscript debugger I can see that it bombs out on the Qry.SQL statement. What am I missing to get an agent to act on every document in the database?





Sub Initialize
      Dim A As String       '*LIMIT STATUS
      Dim H As String
      Dim O As String
      Dim P As String
      Dim S As String
      Dim T As String
      Dim Q As String
      Dim W As String
      
      A = "A"
      H = "H"
      O = "O"
      P = "P"
      S = "S"
      T = "T"
      Q = "Q"
      W = "W"
      
      
      Dim con As New ODBCConnection
      Dim qry As New ODBCQuery
      Dim res As New ODBCResultSet
      
      Dim WS As New notesUIWorkspace
      Dim uidoc As NotesUiDocument
      Dim doc As NotesDocument
      
      Set uidoc = ws.currentdocument
      'Set doc = uidoc.Document
      
      
status=Con.ConnectTo("datasource","id","pw")
If con.geterror<>DBstsSuccess Then
Messagebox con.GetExtendedErrorMessage,,"Could not make connection to AS/400 system"
            Exit Sub
      Else
      End If
      
      Set qry.Connection = Con
      Qry.SQL = "select * from SOFTTURND.TPRJTSK where TRSRC='"+uidoc.fieldgettext("resource")+"'" + "ORDER BY TPTY, TPROJ"
      If qry.geterror<>DBstsSuccess Then
            Messagebox qry.GetExtendedErrorMessage,,"SQL Error"
            con.Disconnect
            Exit Sub
      Else
      End If
      
      
      Set Res.Query = Qry
      
      Res.Execute
      If res.GetError<>DBstsSuccess Then
            Messagebox res.GetExtendedErrorMessage,,"Result Error"
            res.close(DB_CLOSE)
            con.Disconnect
            Exit Sub
            
      Else
            If Not res.IsResultSetAvailable Then
                  Messagebox "No Values Found for your Query"
            Else
                  
                  
                  Dim Counter As Integer
                  Counter = 1
                  
                  Do      
                        Call uidoc.FieldSetText("project_" + Cstr(Counter), "")
                        Call uidoc.FieldSetText("task_" + Cstr(Counter),  "")
                        Call uidoc.FieldSetText("description_" + Cstr(Counter), "")
                        Call uidoc.FieldSetText("requester_" + Cstr(Counter),  "")
                        Call uidoc.FieldSetText("priority_" + Cstr(Counter), "")
                        Call uidoc.FieldSetText("status_" + Cstr(Counter),  "")
                        Counter = Counter + 1                                    
                  Loop Until Counter = 49
                  
                  
                  Counter = 1                  
                  Do
                        res.NextRow
                        
                        If Res.GetValue("TSTS") = S  Or Res.GetValue("TSTS") = H Or Res.GetValue("TSTS") = A Or Res.GetValue("TSTS") = O Or Res.GetValue("TSTS") = P Or Res.GetValue("TSTS") = T Or Res.GetValue("TSTS") = Q Or Res.GetValue("TSTS") = W Then
                              
                              Call uidoc.FieldSetText("project_" + Cstr(Counter), Res.GetValue("TPROJ"))
                              Call uidoc.FieldSetText("task_" + Cstr(Counter),  Res.GetValue("TTASK"))
                              Call uidoc.FieldSetText("description_" + Cstr(Counter),  Res.GetValue("TDESC"))
                              Call uidoc.FieldSetText("requester_" + Cstr(Counter),  Res.GetValue("TRQSTR"))
                              Call uidoc.FieldSetText("priority_" + Cstr(Counter),  Res.GetValue("TPTY"))

Call uidoc.FieldSetText("status_" + Cstr(Counter),  Res.GetValue("TSTS"))
                              
                              
Counter = Counter + 1      
End If
                        
Loop Until res.IsEndOfData Or Counter = 49
                  
                  Counter = Counter - 1
Call uidoc.FieldSetText("count",Cstr(Counter))      
                  
Call uidoc.FieldSetText("date" , Cstr(Date$))
                  
      End If
      End If
      Res.Close(DB_close)
      Con.Disconnect
End Sub
0
Comment
Question by:roosterup
[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
2 Comments
 
LVL 9

Accepted Solution

by:
Arunkumar earned 200 total points
ID: 2802765
Hi Roosterup,

Include these lines to refer doc(The document you select from the view)

Dim ss As New notessession          
Dim db As notesdatabase
Set db = ss.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument

Change all the
Call uidoc.FieldSetText("FieldName",Value) lines to read as

doc.FieldName = Value

MAKE Sure your lines for
Qry.SQL reads as follows

Qry.SQL = "select * from SOFTTURND.TPRJTSK where TRSRC = '"+ doc.resource(0) +"'" + "ORDER BY TPTY, TPROJ"


Also at the end of the script make sure you use the following to save the document

Call doc.Save(True,False)

Good Luck !

-Arun

PS: These Code changes will work for only one document that is selected in the view since we are not looping through documents.
0
 
LVL 1

Author Comment

by:roosterup
ID: 2802855
I would actually like to run this agent on a schedule and have it update all the documents.
0

Featured Post

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!

Question has a verified solution.

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

  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…
Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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