Manage Learn to apply best practices and optimize your operations.

Enable or disable scheduled agents without opening the Lotus Notes database design

Get instructions and LotusScript code that will enable or disable scheduled agents from the Lotus Notes UI without having to open the database design.

This tip provides step-by-step instructions and LotusScript code that will enable or disable scheduled agents from the Lotus Notes user interface -- without having to open the Lotus Notes database design. This can be useful when Lotus Notes Domino developers do not have designer's access to the Lotus Notes production databases.

  1. Create a form with two buttons.

  2. Create six fields and call them: schagentlist, unschagentlist, schagentlist_1, unschagentlist_1, schagentlist_2, unschagentlist_2.

  3. Implement this LotusScript code into the first button:
    "Generate list of agents" code 
    on click-> Dim uiws 
    As New notesuiworkspace
    Dim dbCurrent As notesdatabase
    Dim itemEnabled As notesitem
    Dim itemDisabled As NotesItem
    Dim docDialog As notesdocument
    Dim session As New notessession
    Dim uiDocDialog As notesuidocument
    Set uiDocDialog = uiws.currentdocument
    Set docDialog = uiDocDialog.document
    
    Set dbCurrent = session.currentdatabase
    Set itemEnabled = 
    docDialog.getfirstitem("schagentlist")
    Set itemDisabled = 
    docDialog.getfirstitem("unschagentlist")
     
     
    Forall a In dbCurrent.Agents
    If a.trigger = 1 Then
    If a.IsEnabled Then
    Call itemEnabled.appendtotextlist
    (ReplaceSubstring(a.name,"|","~"))
    Else
    Call itemDisabled.appendtotextlist
    (ReplaceSubstring(a.name, "|", "~"))
    End If
     End If
     End Forall
     
    Call uiDocDialog.refresh
    
  4. Select which agents you'd like to enable or disable in the fields with a single click.

  5. Next, you want to click on the second button to enable or disable the agents -- but first you must paste some LotusScript code onto it. Here is the LotusScript code for the second button:
    Sub Click(Source As Button)
     
    On Error Goto errorhandler
    Dim session As New notessession
    Dim dbCurrent As notesdatabase
    Dim docDialog As notesdocument
    Dim docLookUp As NotesDocument
    Dim uiws As New notesuiworkspace
    Dim uiDocDialog As notesuidocument
    Dim itemEnabled As NotesItem
    Dim itemDisabled As NotesItem
    
    Set dbCurrent = session.currentdatabase
    Set uiDocDialog = uiws.currentdocument
    Set docDialog = uidocDialog.document
    
    If Trim(docDialog.schagentlist_2(0))="" 
    Then
    If Trim(docDialog.unschagentlist_2(0))=""
     Then
     Msgbox "No Selection"
    Exit Sub
    End If
    End If
    Set docLookUp = createAgentLUDoc
    ( dbCurrent, docDialog)
     
    If docLookup Is Nothing Then Exit Sub
    If Not ( runAgentOnServer (dbCurrent, 
    "(ProcessAgentLUDoc)", docLookUp) )
     Then Exit Sub
    If Not ( runAgentOnServer (dbCurrent,
     "(DeleteAgentLUDoc)", docLookUp) ) 
    Then Exit Sub
    
    docDialog.schagentlist =""
    docDialog.schagentlist_1=""
    docDialog.schagentlist_2=""
    docDialog.unschagentlist=""
    docDialog.unschagentlist_1=""
    docDialog.unschagentlist_2=""
    
    'refresh current state of agents..
    Set itemEnabled = 
    docDialog.getfirstitem("schagentlist")
    Set itemDisabled = 
    docDialog.getfirstitem("unschagentlist")
    
    Forall a In dbCurrent.Agents
    If a.trigger = 1 Then
    If a.IsEnabled Then
    Call itemEnabled.appendtotextlist
    (ReplaceSubstring(a.name, "|", "~"))
     Else
    Call itemDisabled.appendtotextlist
    (ReplaceSubstring(a.name,"|","~"))
     End If
     End If
     End Forall
    uiDocDialog.refresh
    Msgbox "Changes Successful!!!", 64, 
    "Step 3"
    
    Exit Sub
    Errorhandler:
    Print "Error in click: " &Err() & " - 
    "&Error() & " @line: " &Erl()
    Exit Sub
    
    End Sub
    
  6. Now, here is the LotusScript code for the first agent, which you can call (ProcessAgentLUDoc):
    Sub Initialize
    On Error Goto errorhandler
    Dim session As New notessession
    Dim db As NotesDatabase
    Dim sdoc As NotesDocument
    Dim agent As notesagent
    Dim cagent As NotesAgent
    
    Set db = session.CurrentDatabase
    Set agent = session.currentagent
    Set sdoc = db.GetDocumentByID
    (agent.ParameterDocID)
    
    If sdoc Is Nothing Then
    Print "cannot find sdoc.."
    Exit Sub
    End If
     
    Forall x In sdoc.schagentlist_2
    Forall a In db.Agents
    If a.trigger = 1 Then
    If ReplaceSubstring(a.Name, "|","~") = x 
    Then
    If Instr(a.Name,"|") = 0 Then
    Set cagent = db.GetAgent(a.Name)
     Else
    Set cagent = db.GetAgent(Strleft
    (Trim(a.Name), "|"))
     End If
    cagent.IsEnabled = False
    cagent.Servername = db.Server
    Call cagent.save
    End If
    End If
    End Forall
    End Forall
     
    Forall y In sdoc.unschagentlist_2
    Forall a In db.Agents
    If a.trigger = 1 Then
    If ReplaceSubstring(a.Name, "|","~") = y 
    Then
    If Instr(a.Name,"|") = 0 Then
    Set cagent = db.GetAgent(a.Name)
    Else
    Set cagent = db.GetAgent(Strleft
    (Trim(a.Name),"|"))
     End If
     cagent.IsEnabled = True
     cagent.Servername = 
    db.Server
     Call cagent.save
    End If
     End If
      End Forall
     End Forall
     
     Exit Sub
    Errorhandler:
    Print "Error in initialize:  " &Err() & " - 
    " &Error() & " @line: " &Erl()
    Exit Sub
    End Sub
    
  7. And finally, here is the LotusScript code for the second agent, which you can call (DeleteAgentLUDoc):
    'to clean up lookup document
    Sub Initialize
    On Error Goto errorhandler
    Dim session As New notessession
    Dim db As notesdatabase
    Dim CurrAgent As NotesAgent
    Dim sdoc As notesdocument
    Set db = session.CurrentDatabase
    Set CurrAgent = session.currentagent
    
    Set sdoc = db.GetDocumentByID
    (CurrAgent.ParameterDocID)
    If Not ( sdoc Is Nothing) Then
    sdoc.Remove(True)
    End If
    Exit Sub
    ErrorHandler:
    Print "Error in DeleteLUDoc: " &Err() 
    & " - " &Error() & " @line: "&Erl()
    Exit Sub
    End Sub
    

You are now ready to enable or disable your scheduled agents without needing to open your Lotus Notes database design.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip library by member Vinay Sharma. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Dig Deeper on Lotus Notes Domino Agents

Join the conversation

1 comment

Send me notifications when other members comment.

Please create a username to comment.

I may be missing something but shouldn't there be functions for runAgentOnServer and ReplaceSubstring? The code gives me multiple errors when I paste it into the designer client. Thanks.
Cancel

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close