
Well, things are slowing down a bit on the personal front (thanks for the supporting comments about that), and I have just started my 4 week vacation. What better way to start the vacation than to add something to my blog? Despite the fact that it isn't thursday, I thought I'd finally get to write a new Show-n-tell thursday entry.
Technorati tag:
Show-n-tell thursday
The subject for the day (well, actually it's the middle of the night here...

) is web agents, and how to pass parameters to a web agent. This is something I've used on occasion, and it can be very useful to know about. This is probably old news to many of you, but judging from some of the questions posted on the
Notes.Net LDD forums, there are still some people that could use this information.
If you have visited my home page before, you might recognize the subject and the code since I've posted about it there. Well, I've decided to move the Banana Home web site completely over to my blog instead, and this is the first step.
So let's get to the point. There are two types of web agents:
- Stand-alone agent
- WebQueryOpen and WebQuerySave agents
There are only minor differences between the two types, and the major difference is the availability of fields. When calling a stand-alone agent, the Domino HTTP server will generate a document containing the necessary fields for the agent. When an agent is called as a WebQueryOpen or WebQuerySave agent, the necessary fields needs to be supplied on the form.
The document is accessed through the NotesSession.DocumentContext property, and the fields are accessed as any other fields on a document. In the example below, I simply go through all the fields on the document, printing the name of the field, and the field value, to a HTML table that will be presented to the user as a web page.
Option Public
Option Declare
Sub Initialize
Dim ns As New NotesSession
Dim doc As NotesDocument
Set doc = ns.DocumentContext
Print |<h2>NotesSession.DocumentContext</h2>|
Print |This is the output from the agent documentcontext|
Print |<p><table border=1 cellpadding=0 cellspacing=0 width="100%">|
Print |<tr><th align=left>Field name</th><th> </th><th align=left>Field value</th></tr>|
Forall item In doc.Items
If item.Name = "SERVER_ADDR" Then
Print |<tr><td align=left>| + item.Name + |</td><td> </td><td align=left><This value has been hidden for security reasons></td></tr>|
Else
Print |<tr><td align=left>| + item.Name + |</td><td> </td><td align=left>| + item.Values(0) + |</td></tr>|
End If
End Forall
Print |</table>|
End Sub
There are two ways of calling this agent: Using a link or using a form. The link would look something like this:
<a href="/users/bananahome/development.nsf/documentcontext?OpenAgent&somefield=somevalue&otherfield=othervalue" target="_blank">documentcontext agent</a>
documentcontext agent
I added some parameters (&somefield=somevalue&otherfield=othervalue) to the link to get some extra information in the agent's output. The form could look something like this:
<form name="documentcontext" method="post" action="/users/bananahome/development.nsf/documentcontext?OpenAgent" target="_blank">
Field 1: <input type="text" name="inputfield1" value="Test value 1"><br>
Field 2: <input type="text" name="inputfield2" value="Test value 2"><br>
Field 3:<br>
<textarea name="inputfield3">Test value 3</textarea><br><br><br>
<input type="submit" value="Submit"><br>
</form>
When using the link, any parameters provided will be in the fields QUERY_STRING and QUERY_STRING_DECODED, but when using the form, the HTML input fields will be in the field REQUEST_CONTENT. The only thing left to do is to parse the values of these fields to make use of them. What you do with them is entirely up to you.
You might notice that the value of the field SERVER_ADDR has been removed. Well, what this field contains is the TCP/IP address of the Domino server, and since I don't want to display any details of my LAN to the internet, I made sure that this information would not be visible. That is what the "If" in the LS above is all about.
When using this kind of agent as a WebQueryOpen or WebQuerySave agent, you need to supply these fields on the form to be able to use them. The DocumentContext document will not be created for you by Domino. It will have to be created by you, including these fields. Normally, you would add them as hidden, Computed for display fields, with the field name as the formula for each field. Doing this, the fields will be accessible the same way as they are here.