Manage Learn to apply best practices and optimize your operations.

A single form to view and edit any Lotus Notes document member Leonard Volovets explains how you can build a dynamic HTML form to view and edit Lotus Notes documents using a Web browser.


Conventional wisdom holds that a rich client like Lotus Notes is superior to a thin client like a Web browser. This is true in most cases. However, there is one Lotus Notes-related situation in which only a Web browser will do.

As an example scenario, let's say you have one or more documents with dynamic content -- i.e., the field names are different. Even worse, perhaps you don't even know what the field names/values are ahead of time. The challenge is to create a form that allows for the viewing and editing of such documents.

Lotus Notes is a powerful application, but it doesn't offer any way (that I'm aware of) to create a design element on the fly. Even if there was, it would be much too complicated for an ordinary Notes/Domino developer to make it worthwhile. This leaves us with the Web browser.

The solution to the problem is surprisingly simple. Build a Lotus Notes form that generates a dynamic HTML form based on the content of the document being viewed/edited.

In fact, the solution I'm proposing contains just one Lotus Notes field and one Computed Text value. There are also two agents: a WebQueryOpen agent called "LoadDocData" and a WebQuerySave agent called "SaveDocData".

We'll call the form "Data" so we can refer to it in the code that follows. In addition, let's assume that the Form field in these documents is set to "Data" to make it all work.

(WebQueryOpen) Agent LoadDocData 
(variable declarations omitted for brevity):

NOTE: In the code below, the agent uses the doc.items property to cycle through all the fields in the document and creates an HTML form with editable fields. I advise alphabetically sorting the fields, which was not done here, to make finding document fields on the screen easier.

All the field names and their values point back to a field called $$Record, a name that was arbitrarily chosen by me. When the Lotus Domino server sees this field, it "stuffs" all the data into a single field, making it a multi-value text list. This field plays a central role in the WebQuerySave agent, as you shall see shortly.

Sub Initialize
Set s = New NotesSession
Set sdoc = s.DocumentContext
Set db = s.CurrentDatabase
ts =  |<table border=1 
cellspacing=0 width=80% 
<tr valign=top><td colspan=2 
bgcolor="808080" align="center">
<b><font size="4" 
color="FFFFF">Document Data<
<tr valign=top><td 
width=20%><b>Field Name<
/b></td><td width=60%><
b>Field Value</b></td></tr>|
 te = |</table>|
 rs = |<tr valign=top>|
 re = |</tr>|
 cs = |<td><font size=2>|
 ce = |</font></td>|
 Forall f In sdoc.items
nam =
If (Instr ( nam, "$" ) Or Instr (Lcase ( nam ) , "form" ) ) Then
'do nothing, do not expose internal fields
values = f.values    
fieldHTML = |<input name="$$Record" 
type="hidden" value="| & nam & |"
><input name="$$Record" 
value="| & values(0) & |" size="25" 
editrow =  rs & cs & nam & ce 
& cs & fieldHTML & ce & re
editbody = editbody & editrow
End If   
End Forall
edittable = ts & editbody & te
Call sdoc.ReplaceItemValue ( "EditTable" , edittable )
End Sub

(WebQuerySave) Agent SaveDocData 
(again, declarations dropped for sake of brevity)

(In this agent, the field $$Record is 
inspected to identify changes to fields. 
Since the structure of the $$Record is 
"name," "value," "name," "value," etc., 
we can easily identify and set appropriate
 fields with new values.)

Sub Initialize
Set s = New NotesSession
Set sdoc = s.DocumentContext
Set db = s.CurrentDatabase
record = sdoc.GetItemValue ("$$Record" )
For n% = Lbound ( record ) To Ubound ( record )
remainder = n% Mod 2
If remainder = 0 Then
fn = record (n%)
tmpvalue = Trim$ ( record (n%) )
Call sdoc.ReplaceItemValue ( fn, value )
End If
End Sub

To put it all together, create a form called "Data" with a field called $$Record (type text, computed, allow multiple values, hidden) and a computed (pass-thru HTML) text value that has the following formula: @If (@IsDocBeingEdited ; EditTable ; ReadTable ), where ReadTable could be the read-only equivalent of the EditTable field calculated in the "LoadDocData" agent above.

Make the "LoadDocData" run on the WebQueryOpen event and "SaveDocData" on the WebQuerySave event and you're done.

Of course, the "Save" link should be provided with the code @Command ( [FileSave] ); @Command ( [FileCloseWindow] ) running behind it.

To make the form a bit more useful, you can check for input/edit errors and dump them into a field called $Errors, which will display if there is something in it.

As a final window-dressing, you could have a $$Return field with the formula: @If (@IsAvailable($Errors) ; "… come back to the edit URL…" ; "… go to some other URL… "). Notice that the agent code assumes single-value fields by working with value(0) part of the field -- but it could certainly be modified to work with more complex data types.


If you need to create actual fields, views, forms, etc., you could also use NotesDXLImporter. It can be somewhat tricky at times though.
—Anders G.

Do you have comments on this tip? Let us know.

Related information from

  • Tip: How to create a comments field for Lotus Notes documents
  • Tip: Update a field in all Lotus Notes documents using an agent
  • Expert Advice: Dynamically create fields in Lotus Notes
  • Reference Center: Agents tips and resources
  • Reference Center: LotusScript tips and resources

    This tip was submitted to the tip library by member Leonard Volovets. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

  • This was last published in January 2007

    Dig Deeper on Lotus Notes Domino Agents

    Start the conversation

    Send me notifications when other members comment.

    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

    Please create a username to comment.




    • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

    • V6R1 upgrade planning checklist

      When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

    • Connecting multiple iSeries systems through DDM

      Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...