One of my clients recently wanted to create a new document based on values entered in a Web form when a button was pressed, BUT didn't want the user to have to submit the form to trigger the agent. This had to happen completely in the background without a round trip to the server and even better; the agent was located in a different database on a completely different server hosted in another domain.
Here's how I did it...
Code
On the user Web form, I created a small image that was an invisible GIF using an HTML image tag. This serves as a placeholder for the image I want to return from an agent later on.
<img src="server/database/invisible.gif" name="image1">
On a button labeled "Create Document", I placed the following JavaScript code:
document.forms[0].image1.src="/server/database/createdoc?openagent&id=" + form.data.value;
This JavaScript replaces the invisible GIF with a new image, in this case one returned by the LotusScript agent called "createdoc".
In the target Domino database, I wrote a LotusScript agent to create the required document and return an image to the browser. I used the query_string_decoded CGI variable to pass data from the Web form to the new document.
'Create a document and return an image to the browser
Dim session As New NotesSession
Dim Webdoc As NotesDocument
Set Webdoc = session.DocumentContext
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim doc As New NotesDocument(db)
doc.query = Webdoc.query_string_decoded(0)
if doc.Save(True,True) then
'Show a tick in the browser if all is well
Print "[http://servername/database.nsf/cross.jpg?OpenImageResource]"
else
'Show an x to indicate the document wasn't created
Print "[http://servername/database.nsf/tick.jpg?OpenImageResource]"
end if