Function scheduledAgentSetEnabled(enable As Boolean, scheduledAgentName As String) As Boolean
'***************************************************************
'@Purpose : To enable or disable a scheduled agent
'@Name : scheduledAgentSetEnabled
'@Author : Karthikeyan A
'@Return : Boolean. True if the operation completes successfully and false other wise
'***************************************************************
'mark the flow of control getting inside the current function
scheduledAgentSetEnabled=False
'constants used in this function
Const TITLE_ITEM="$Title"
Const ASSIST_FLAG_ITEM="$AssistFlags"
'declare variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim currDB As notesdatabase
Dim nc As notesnotecollection
Dim desDoc As NotesDocument
Dim noteID As String
Dim assistFlags As String
'handle errors in case of abrupt termination
On Error Goto errHandler
'set the handle for the current database
Set currDB=session.CurrentDatabase
'get the notes collection of all the agents in the current database
Set nc=currDB.CreateNoteCollection(False)
nc.SelectAgents=True
Call nc.BuildCollection()
'get the first noteid from the notes design document collection
noteID=nc.GetFirstNoteId
'loop through the design document collection using the noteIDs and enable or diable the agent whose title matches
'input parameter- agent name
Set desDoc=currDB.GetDocumentByID(noteID)
While Not desDoc Is Nothing
If Ucase(desDoc.GetItemValue(TITLE_ITEM)(0))=Ucase(scheduledAgentName) Then
assistFlags=desDoc.GetItemValue(ASSIST_FLAG_ITEM)(0)
If enable Then
If Not Instr(Ucase(assistFlags),"E") Then
assistFlags=assistFlags & "E"
End If
Else
While Instr(Ucase(assistFlags),"E")
assistFlags=Replace(Ucase(assistFlags),"E","")
Wend
End If
Call desDoc.ReplaceItemValue(ASSIST_FLAG_ITEM,assistFlags)
Call desDoc.Save(True,False)
End If
noteID=nc.GetNextNoteId(noteID)
Set desDoc=currDB.GetDocumentByID(noteID)
Wend
'mark the flow of control moving out of the current function
scheduledAgentSetEnabled=True
Exit Function
'inform the user regarding the errors that resulted in abrupt termination
errHandler:
If Err=4270 Then Exit Function
Msgbox "Error ***" & Error & "*** occured in line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) & "*** in agent scheduledAgentSetEnabled(enable As Boolean, agentName As String)"
Print "Error ***" & Error & "*** occured in line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) & "*** in agent scheduledAgentSetEnabled(enable As Boolean, agentName As String)"
Exit Function
End Function
No comments:
Post a Comment