To populate a field on a Web form, you call an agent which displays a combobox in a popup-window where you can select a view-entry from a view of unlimited size.
The agent is reusable because you pass him variables for the view to search and the field to populate.
In the given example I use the following elements:
View 'Aufnr'
Field 'Aufnr_'
Agent 'GenerateDialog'
On the form use a button with Javascript:
var pathname = window.location.pathname);
url=pathname.substring(0,(pathname.lastIndexOf(".nsf")+5))+"GenerateDialog?OpenAgent&View=Aufnr&Field=Aufnr_";
window.open(url,"GenerateDialog","width=480,height=40,left=200,top=300");
Then create a LotusScript-Agent (manually from agent list, Run Once):
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim vc As NotesViewEntryCollection
Dim entry As NotesViewEntry
Dim doc As NotesDocument
Dim strVIEW,strFIELD As String
Dim querystring As String
Dim Params List As String
Dim i As Integer
Set db = session.CurrentDatabase
Set doc = session.DocumentContext
' pull the query_string from the DocumentContext which represents an instance of this agent
querystring=doc.query_string(0)
i = Instr(querystring, "&" )
Do While i>0
querystring = Mid(querystring, i+1)
i=Instr(querystring,"=")
If i>0 Then
' Get the Variable Name
varname = Left(querystring,i-1)
Else
Exit Do
End If
querystring=Mid(querystring, i+1)
i=Instr(querystring,"&")
If i>0 Then
' Get the Value
value = Left(querystring, i-1)
Else
value=querystring
End If
' Save the Parameter in the list
Params(varname)=value
Loop
strVIEW=Params("View")
strFIELD=Params("Field")
Set view = db.GetView(strVIEW)
Set vc = view.AllEntries
' Generate the HTML-Doc
Print "Content-Type: text/html"
Print ""
Print "<HTML><HEAD>"
Print "<SCRIPT LANGUAGE=""JavaScript"">"
Print "<!--"
Print "function CheckSelection() {"
Print "var frm=window.document._GenerateDialog;"
Print "for(i=0;i<frm.Sel.length;++i)"
Print "if(frm.Sel.options[i].selected == true)"
Print "frmMain."+strFIELD+".value=frm.Sel.options[i].text"
Print"self.close();"
Print "} // -->"
Print "</SCRIPT>"
Print "<TITLE>Bitte wahlen Sie einen Eintrag</TITLE></HEAD>"
Print "<BODY BGCOLOR=""DAFBFE"" onLoad=""frmMain = window.opener.document.forms[0]"">"
Print "<FORM METHOD=post NAME=""_GenerateDialog"">"
Print "<BR>"
Print "<CENTER>"
' Fill in the Options
Print "<SELECT NAME=""Sel"" onChange=""CheckSelection()"">"
Print "<OPTION>----- Please select -----<SELECTED>"
For i = 1 To vc.count
Set entry=vc.GetNthEntry(i)
Print "<OPTION>" + Cstr(entry.ColumnValues(1))
Next
Print "</SELECT><BR>"
Print "</BODY></FORM></HTML>"
End Sub
This was first published in September 2001