As you know, there are some things that are best done (or can only be done) in LotusScript, and some that are best done in formula language. The problem is that agents, actions, and so on are restricted to one language -- formula, LotusScript, or Java. But there is a way to combine script and formula language. You can have formula call script or script call formula language using an agent.
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
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