Hi
Scenario:
======
I need to hide the design of a database template which is to be installed in
different organisations. The application contains a scheduled agent that I need
to control. I need to set on which server it runs, at what interval, and on
behalf of whom it runs (typically the server since it accesses other servers
and we need to set up trust between them). The agent has to be set to "Allow
restricted operations" since I run some Java code using external JAR-files to
call a webservice
I have created a new copy of the template with hidden design. This effectively
hides all designelements. However, I can create a new agent directly in this
database - but only as a private agent! So I cannot use this as a solution.
From LotusScript I can set the server to run the agent on and I can
disable/enable the agent. But I cannot set the schedule nor whom to run the
agent on behalf of.
DXL:
===
So I tried use DXL. For simplicity the steps below have all been carried out on
a database where the design has not been hidden. I have exported the agent and
tried to modify the data I need to adjust and reimport the agent. First
observations are:
-
I cannot import an agent that use simple actions
-
I cannot import an agent that use Formula language
In both cases I get the message: "This action cannot be recognized by this
version of Lotus Notes"…
However, I found out through an example here in the forum (http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/
7f97d5c3b3d1a763852570890054833f?OpenDocument)
that I can import a LotusScript agent. And that all seems fine when I look at
the code, properties, etc.
But it does not trigger!!
If I manually recreate the agent with exactly the same settings it will run Ok.
Procedure to reproduce:
================
Create an agent that you want to export/import. I called mine “Event Listener”
and used the following code:
Dim s As New NotesSession
Dim agt As NotesAgent
Set agt = s.currentDatabase.getAgent("(wsListener)")
If Not agt Is Nothing Then
Call agt.run()
End If
Set the agent to be scheduled e.g. every 10 minutes and set the agent to run on
behalf of your server and to allow restricted actions. Save the agent, check
that it runs as scheduled, and disable it.
Now open the agent again and select Tools\DXL Utilities\Exporter… in the
menus and point to a text file. In this example I used d:\temp\NewAgent1.dxl. I
selected format “DXL file” but I haven’t really noticed any difference between
that and “XML file” format.
Now create a new agent to import the other agent. I used this code:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim filename As String
Set db = session.CurrentDatabase
filename$ = "d:\temp\NewAgent1.dxl"
REM Open dxl file
Dim stream As NotesStream
Set stream = session.CreateStream
If Not stream.Open(filename$) Then
Messagebox "Cannot open " & filename$,, "Error"
Exit Sub
End If
If stream.Bytes = 0 Then
Messagebox "File did not exist or was empty",, filename$
Exit Sub
End If
REM Import DXL into new database
Dim importer As NotesDXLImporter
Set importer = session.CreateDXLImporter(stream, db)
importer.ReplicaRequiredForReplaceOrUpdate = False
importer.DesignImportOption = DXLIMPORTOPTION_REPLACE_ELSE_CREATE
Call importer.Process
' Sign the imported agent...
Dim nc As NotesNoteCollection
Dim noteId As String
Dim doc As NotesDocument
Set nc = db.CreateNoteCollection(False)
nc.SelectAgents = True
nc.SelectionFormula = "@LowerCase($Title)=""event listener"""
Call nc.BuildCollection
If nc.Count > 0 Then
noteId = nc.GetFirstNoteId()
Set doc = db.GetDocumentByID(noteId)
Call doc.Sign()
Call doc.save(True,False)
End If
Please note that you need to know the name of the agent to sign it as part of
importing it.
Now remove the first agent (“Event Listener” in my example) from your database
and run the second agent to reimport the scheduled agent. Enable the newly
imported agent from the agent list and wait… It does not trigger - at least
not on my server. You can open the agent and check all the settings. They seem
to be correct.
Subsequently, I have tried to change the agents LotusScript code and save the
agent. It still does not trigger!
Any advice as to where I am going wrong would be greatly appreciated! This is a
really nice feature if we can make it work.
Regards
John
PS. Sorry for the long description, but I thought I would show the code for you
to try yourself ![]()