Building/Generating: Lotus Script Code on the fly

I created a button tool that adds an appointment to a persons calendar and send back an optional e-mail.

The button adds the appointment to their calendar setting the date, time, chair, body, etc. I customized the code so my user community only needs to go into the declaration section and file in the blanks and the button does exactly what they want:

Please indicate which session you will attend (no code behind buttons):

What I would like to do is develop a Lotus Notes database that allows the users to fill in the “blanks” on a form and it develops the buttons.

I create a SIMPLE case where the button reference backend fields unique for each button.

button1_StartDate

button1_StateTime

button1_EndDate

button2_StartDate

button2_StartTime

It works, but I’m not happy with it because the backend fields are lost if the e-mails forwarded to someone else.

I’m curious if it’s possible to generate the button on the fly with all the variables set in the declaration section?

Clearly, I don’t expect anyone to write the whole thing for me… Please point me in the right directtion.

Something like this would be a great starting point:

Options Explicit

Const MsgSrt$=“Set on Form”

Sub Click

MsgBox(MsgStr$)

End Sub

So I would then have a form where I fill in a text field, say Hello World and then it produces a button with the above code with MsgStr changed from “Set on Form” to “Hello World”

MsgStr$=“Hello World”

Any ideas?

Subject: Building/Generating: Lotus Script Code on the fly

The only way I can think of to make the code stand alone is to create the mail using DXL. Create a “template mailer” and export the document to a file. You should be able to read the file and see where the LS source code and button labels are stored in the XML document. Developing code to modify the appropriate document nodes should be relatively easy. In production, take the “template” document and export it to a NotesDOMParser, then use the end-user information to modify the document. Re-import the doc as a new document – the button labels should be correct, and the LS code behind the buttons will be compiled and ready to rock.

Subject: RE: Building/Generating: Lotus Script Code on the fly

Thanks Stan,

I was guessing this was the direction I was going to have to go, as I’ve played with the sandbox tool to add smart icons buttons and it seems to work this way.

Up to now I’ve never looked at the DXL stuff, so it’s time to learn.

Subject: Building/Generating: Lotus Script Code on the fly

You can use XML to dynamically create the buttons with LotusScript, and have the new button(s) added to the Body of an email.

One method would be to export an email as XML using the DxlExporter class, modify the stream to add your button with its new LotusScript, then use the DxlImporter class to update the email with the modification.

There are a number of ways to do this, with which you will need to experiment. To get an idea, export an existing email to XML file, and take a look at the output. You can export a document to an XML file using the following function:

Function ExportXML ( doc As NotesDocument ) As String

'To export the files to DXL use this function

Dim s As New NotesSession

Dim stream As NotesStream

Set stream = s.CreateStream

Dim exporter As NotesDXLExporter

Dim FILENAME As String

Dim universalID As String*32

Const PATHNAME = "c:\"



universalID = doc.UniversalID



FILENAME = PATHNAME + universalID +".xml"

If Not stream.Open ( FILENAME ) Then

	Messagebox "Cannot open " & FILENAME,, "Error"

	Exit Function

End If

Call stream.Truncate



Set exporter = s.CreateDXLExporter

Call exporter.SetInput ( doc )

Call exporter.SetOutput ( stream )

Call exporter.Process

ExportXML = FILENAME

End Function

To then view the XML file with a WebBrowser, place the XML file in your Notes program folder. The WebBrowser will need the “xmlschemas” subfolder for the viewing to work. But this is necessary only for you to view the XML of a NotesDocument. You don’t need it to Import XML to create or modify a NotesDocument.

Subject: RE: Building/Generating: Lotus Script Code on the fly

Thanks James, for the code sample. Off to learn about DXL.

Subject: Building/Generating: Lotus Script Code on the fly

In a round-about way, you have described a common issue that sometimes is solved by storing the form in the document. Rather that to try to attack the button itself, attack the form. Rather that letting the users forward the button or document (which will send it as a memo), add a button to the top labeled [Forward]. What this button will do is to send it using a form with the form embedded. That way all of the fields go with it.

Subject: RE: Building/Generating: Lotus Script Code on the fly

Thanks Doug, it’s a good idea but not in the context of what I’m hoping to ultimately achive - a tool that will generate buttons on the fly they can cut and paste into e-mails.