Administrative Server and Am I Template Checks for Agents

Mindwatering Incorporated

Author: Tripp W Black

Created: 01/02/2013 at 01:35 PM

 

Category:
Notes Developer Tips
LotusScript

Issue:

Have an agent that you'd like to do two checks:

1. Verify the agent is not running if the application is a template (without a NTF extension).
2. Not hard-code in the agent properties to run on a specific server. Desire instead to set the agent properties to run on Any Server and check if the current server is the Administrative Server for the current app smartly.


Solution:

Below is a code sample:

Sub Initialize
Dim s as New NotesSession
Dim db as NotesDatabase ' current app
. . .
' setup
Set db = s.CurrentDatabase
' abort if template
If Not (db.TemplateName = "") Then
' this is a template, abort
Exit Sub
End If
' abort if not on ACL admin server
If Not (CheckAdminServer(db) = 1) Then
Exit Sub
End If
. . .
End Sub

Function CheckAdminServer(db As NotesDatabase) As Integer
' checks to see if current server running an agent is the current server, returns 1 for same, 0 for different or failure
Dim dbACL As NotesACL ' current db ACL, check to see if running on admin server
Dim adminNm As NotesName ' admin server from ACL
Dim curNm As NotesName ' current server running agent (db)

On Error Goto FErrorHandler

CheckAdminServer = 0

' get acl admin, set names, and compare
Set dbACL = db.ACL
Set curNm = New NotesName(db.Server)
Set adminNm = New NotesName(dbACL.AdministrationServer)
If (Strcompare(curNm.Abbreviated, adminNm.Abbreviated, 5)=0 ) Then
' match
CheckAdminServer = 1
Exit Function
End If

FExit:
Exit Function

FErrorHandler:
Resume FExit
End Function


Function GetAdminServer(db As NotesDatabase) As String
' checks to see if current server running an agent is the current server, returns 1 for same, 0 for different or failure
Dim dbACL As NotesACL ' current db ACL, check to see if running on admin server
Dim adminNm As NotesName ' admin server from ACL
Dim curNm As NotesName ' current server running agent (db)

On Error Goto FErrorHandler

GetAdminServer = 0

' get acl admin, set names, and compare
Set dbACL = db.ACL
Set adminNm = New NotesName(dbACL.AdministrationServer)
If Not (adminNm Is Nothing) Then
' use admin server
GetAdminServer = adminNm.Canonical
Else
' use current server
GetAdminServer = db.Server
End If

FExit:
Exit Function

FErrorHandler:
Resume FExit
End Function




previous page