Tip: Get database agent status with one click!

All Agent Status Report

Return to article

Sub Initialize
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim agent As NotesAgent
	Dim runDate As Variant
	Dim agentName As String
	Dim MSGString As String
	
	Dim crlf As String
	Dim cr As String
	Dim lf As String
	
	cr$=Chr(13) ' Carriage return
	lf$=Chr(10) ' line feed
	crlf$=Chr(13) & Chr(10) ' Carriage return/line feed
	TBR$ = Chr(9)
	
	Set db = session.CurrentDatabase
	'Set agent = session.CurrentAgent
	'agentName = "HelloWorld in LotusScript"
	'Set agent = agentName
	'Set agent.name = "HelloWorld in LotusScript"
	
	Forall a In db.Agents
		
		Set agent = a
		runDate = agent.LastRun
		AgentSigner = agent.owner
		MSGString = MSGString & " " & Cstr(a.Name) & " " & runDate & CR$_
		 & " Agent Signer = " & AgentSigner & Cr$ & cr$
		
	End Forall
	MSGString = MSGString & CR$ & "  Note: 12:00 AM = Agent Never Run " & CR$
	runDate = agent.LastRun
	'agentName = agent.Name
	
	message$ = MSGString
	
	answer% = Messagebox(message$, boxType&, _ 
	"Lotus Database " & DB.Title & " Agent Last Run Date Report")
 ' 1 is the return value for pressing OK
	If(answer% = 1) Then
		Goto Cont ' OK was pressed so Continue script
	Else
		Exit Sub ' If another box type is used with a choice, then an alternative path may be taken.
	End If
Cont:
End Sub

Variation: All Agent Status Report of agents in a different database

With some code changes, you can use the All Agent Status Report to find the status of agents in another database.

NOTE: Delays are needed for proper reporting after the other database is opened. See Sleep(2.0) statements where 2.0 is two seconds and may vary in your environment. If delay time is not sufficient, the current database agents are shown!

To get a handle on a different agent in the database to find the last run date and time, use the following. (NOTE: Do not set agent = session.CurrentAgent.)

Sub Initialize
	On Error Goto GeneralErr ' put at very top before Dimension statements
	' Define the carriage control
	Dim cr As String	
	' The following 3 statements are needed for the Notes Version of Software Running this DB.
	Dim session As New Notessession
	Dim version As String
	version = session.NotesVersion
	Dim workspace As New NotesUIWorkspace
	
	Dim db As NotesDatabase
	Dim dbtServer As String
	dbtServer = "CN=CAMDB99/OU=CAM/OU=A/O=Lotus" ' Change to your Server
	Dim agent As NotesAgent
	Dim runDate As Variant
	Dim agentName As String
	Dim MSGString As String
	
	Dim crlf As String
	'Dim cr As String
	Dim lf As String
	
	cr$=Chr(13) ' Carriage return
	lf$=Chr(10) ' line feed
	crlf$=Chr(13) & Chr(10) ' Carriage return/line feed
	TBR$ = Chr(9)
	
	Call workspace.OpenDatabase _
	( dbtserver, "L_Dir\DBname.nsf") ' Change to Your DB
	', , , False, False )
	Sleep(2.0)
	Set db = session.CurrentDatabase
	Sleep(2.0)
	Forall a In db.Agents
		
		Set agent = a
		runDate = agent.LastRun
		AgentSigner = agent.owner
		Sleep(0.5)
		'MSGString = MSGString & " " & Cstr(a.Name) & " " & runDate & CR$ _
		& " Agent Signer = " & AgentSigner & Cr$ & cr$
		MSGString = MSGString & " " & Cstr(a.Name) & " " & runDate & CR$ _
		& " Agent Signer = " & AgentSigner & Cr$
		
	End Forall
	MSGString = MSGString & CR$ & "  Note: 12:00 AM = Agent Never Run " & CR$
	runDate = agent.LastRun
	
	message$ = MSGString
	
	answer% = Messagebox(message$, boxType&, _ 
	"Lotus Database " & DB.Title & " Agent Last Run Date Report")
 ' 1 is the return value for pressing OK
	If(answer% = 1) Then
		Goto Cont ' OK was pressed so Continue script
	Else
		Exit Sub ' If another box type is used with a choice, then an alternative path may be taken.
	End If
Cont:
	Goto TEnd
GeneralErr:
	message$ = " " & cr$ _
	& " An error was encountered in executing. " & cr$ _
	& "  Error # = " + Str(Err)+ cr$ _
	& "  Error String = " + Error$ + cr$_
	& "  Error Line # = " + Str(Erl) + cr$_
	& " Report this error to your DB Designer with the following information " + cr$ _
	& " The Notes Version Running this DB = " + version + cr$ _
	& " Error in LotusScript Code" + cr$ _
	& " Type and Name = Action Button --Agent Status-- " + cr$ _ 
	& " Database Title = " + db.Title + cr$ _
	& " Database Filename = " + db.Filename + cr$ _
	& " Database Directory Path = " + db.Filepath + cr$ _
	& "" + cr$_
	& " Click OK to continue - Cancel to quit "
	
	boxType& = 17 ' MB_OKCANCEL + MB_ICONStop
	answer% = Messagebox(message$, boxType&, _ 
	"Error in execution of LS Code!")
	If(answer% = 1) Then
		Goto ContResN ' OK - Continue with next statement in LotusScript
	Else
		Exit Sub ' Cancel so quit out.
	End If
ContResN:
	Resume Next
TEnd:
End Sub

Return to article