Tip

Linking Script and Formulas

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.

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.