Let's say that you had two tasks to perform on a document, to be launched from a button on a form. The first task requires formula language, the second requires script. The trick is to write the code for the second task in an agent. Then you call the agent from the first task and pass a parameter so that the agent knows which document to work on.
To do this, I use the following technique:
1) Capture the document's UNID
2) Record the UNID in the notes.INI or a profile document
3) Run the agent
In the agent:
1) Get the document's ID from the Notes.INI
2) Retrieve the document
3) Perform tasks
There's some sample code below. In this example my agent is called Agent1. The button is formula language and the agent is LotusScript.
I haven't done it here, but it's a good idea to:
1) Verify that you find the document after calling the GetDocumentByID method
2) Erase the environment variable after use
This technique could be expanded in the following ways:
1) Passing multiple document IDs
2) Passing a database ID as well as a document ID
Button code
REM "Perform formula tasks here";
REM "and get the doc's UNID";
DocID := @Text(@DocumentUniqueID);
REM "Now write it to the notes.ini";
@SetEnvironment( "MyDoc" ; DocID );
REM "Now run the agent";
@Command([ToolsRunMacro];"Agent1");
Agent code
Sub Initialize
'Dim variables
Dim sess as new NotesSession
Dim DB as NotesDatabase
Dim doc as NotesDocument
Dim DocID as String
'Get the document ID from Notes.ini MyDoc variable
DocID = sess.GetEnvironmentString("MyDoc")
'Get the current database and the specified document
Set db = sess.CurrentDatabase
Set doc = db.GetDocumentByID(DocID)
'Perform script tasks here
End Sub
This was first published in April 2001