Tip

Calling agent from Web without submitting a form

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...

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

This was first published in May 2002

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.