1
votes

I have 6 agent, 1 form("Agent Status"), 1 view("Agent Status List"), & 1 script library("Process Agent").

Form fields: AgentName(stores the name of an agent), LastDate(last run date & time of agent)

View: Based on the form. AgentName is 1st column.

Each agent is named as follows(with parentheses): (Agent01), (Agent02), (Agent03), (Agent04), (Agent05), & (Agent06)

script libary code

Option Public
Option Declare

Dim vw As NotesView, doc As NotesDocument

Sub Initialize
End Sub

Sub setLastRun(db As NotesDatabase, a As NotesAgent, dte)   
    Set vw=db.Getview("Agent Status List")
    Set doc=vw.Getdocumentbykey(a.Name, True)
    If doc Is Nothing Then
        Set doc=New NotesDocument(db)
        doc.form="Agent Status"
        doc.AgentName=a.Name
        doc.LastDate=CDat(dte)
        Call doc.save(True, True)
        Call vw.Refresh()
    Else
        Call doc.Replaceitemvalue("LastDate", CDat(dte))
        Call doc.Save(True, True)
        Call vw.Refresh()
    End If  
End Sub

Function getLastRun(db As NotesDatabase, a As NotesAgent)
    Set vw=db.Getview("Agent Status List")
    Set doc=vw.Getdocumentbykey(a.Name, True)
    If Not doc Is Nothing Then
        getLastRun=doc.LastDate(0)
    Else
        Call setLastRun(db, a, Now)
        getLastRun=CDat(Now)
    End If
End Function

In each of the agent's code, I include the following:

At the top: Use "Process Agent"

At the beginning of the code(get the last run date of this agent from the "Agent Status List" view):

Dim s As New NotesSession, db As NotesDatabase
Dim a As NotesAgent, lastdate
Set db=s.Currentdatabase
Set a=s.Currentagent
lastdate=getLastRun(db, a)

At the end of the code(set a new last run date for this agent): Call setLastRun(db, a, now)

The problem now is it can't seem to lookup for the agent name in the "Agent Status List" view.

The description for agent name lotus help file is: Read-only. The name of an agent. Within a database, the name of an agent may not be unique.

When I look at the view, it always create a new document each time instead of referring and updating the existing one. The name in the view appear as "Agent01" only without the parentheses. Is that the cause? Or because of the description that the name is not unique therefore can't be lookup-ed. I don't understand this. If everything is ok, there should be only 6 documents in the view.

1

1 Answers

1
votes

GetDocumentByKey is returning Nothing. The most likely cause is that you have forgotten to set the sort property on the first column of your "Agent Status List".