|

 | [Back to Developing an advanced settings tool]
agtNamePicker agent
Sub Initialize 'agtNamePicker
'This agent searches the Address Book for the supplied name and generates an HTML page listing the possible matches on
' that name as radio buttons.
'Sample call (JavaScript in an action hotspot):
'window.open('http://' + document.forms[0].ServerAndPath.value + '/agtNamePicker?OpenAgent&' + document.forms[0].fUserAdd.value + "&fUser&1", 'VerifyUser', 'width=500,height=300,resizable=yes,scrollbars=yes')
'Parameters:
'- You should pass exactly three parameters in the URL calling this agent, in this order:
' - strSearchFor (string): The search value the user typed in
' - strDestField (string): The field in which to store the selected name
' - bMulti (0 or 1): Whether strDestField supports multiple values. If true, new names are separated using commas
'Known bugs:
'- Netscape 6 ignores the OK button
'
'Sample output:
'<HTML>
'<!-- Lotus-Domino (Release 5.0.5 - September 22, 2000 on Windows NT/Intel) -->
'<HEAD>
'</HEAD>
'<BODY TEXT="000000">
' <script> function addNames() {
' window.opener.document.forms[0].fValueName.value = Temp.value;
' window.close();
' }
' </script>
'Search for users with name containing the word - duck - found these matches. Please select one:<br><br>
'<INPUT NAME="Temp" TYPE=hidden VALUE="">
'<INPUT TYPE=radio NAME="SelectUser" VALUE="Daffy Duck" onClick="Temp.value='Daffy Duck'">Daffy Duck<br>
'<INPUT TYPE=radio NAME="SelectUser" VALUE="Donald Duck" onClick="Temp.value='Donald Duck'">Donald Duck<br>
'<BR><DIV ALIGN=center><INPUT TYPE=button onClick="addNames()" VALUE="OK">
'<INPUT TYPE=button onClick="window.close()" VALUE="Cancel"><DIV>
'</BODY>
'</HTML>
Dim session As New NotesSession, doc As NotesDocument
Dim strSearchFor As String
Dim varMatches As Variant
Dim varTemp As Variant, strTemp As String, strNewValue As String
Dim varParms As Variant, strDestField As String, bMulti As Integer, bFound As Integer
On Error Goto Errorhandler
Set doc = session.DocumentContext
'Parse out the three parameters from the CGI string.
'Examples: "?OpenAgent&Smith&fUserName&1", "?OpenAgent&&fUserName&0"
strTemp = |@Explode ( @Right("| + doc.Query_String_Decoded(0) + |";"&"); "&" ) |
varParms = Evaluate (strTemp)
bFound=False 'Assume the worst: no match will be found
If Ubound (varParms) = 2 Then
'We got all the parameters
strSearchFor = varParms(0)
strDestField = varParms(1)
bMulti = Cint( varParms(2) )
strNewValue = "Temp.value"
strTemp = |@unique(@NameLookup ( [Exhaustive]; "| + strSearchFor + |" ; "Fullname"))|
varMatches = Evaluate(strTemp)
If (Ubound(varmatches) >= 0) And (varmatches(0) <> "") Then
'Match(es) found! Build JavaScript and radio buttons to present the names and process the user's selection.
bFound = True
'Create the script called by the OK button
Print | <script> function addNames() {|
If bMulti Then
'The OK button should append the selected name to any existing names in the strDestField field.
Print | var strOld = window.opener.document.forms[0].| + strDestField + |.value;|
Print | if ( strOld == "") {|
Print | window.opener.document.forms[0].| + strDestField + |.value = | + strNewValue + |;|
Print | }|
Print | else {|
Print | window.opener.document.forms[0].| + strDestField + |.value = strOld + ", " + | + strNewValue + |;|
Print | }|
Else
'The OK button should write the selected name over any existing name in the strDestField field.
Print | window.opener.document.forms[0].| + strDestField + |.value = | + strNewValue + |;|
End If
Print | window.close(); } </script>|
'Create the body that displays the matches
Print "Search for users with name containing the word - " & strSearchFor & " - found these matches. Please select one:<br><br>"
Print |<INPUT NAME="Temp" TYPE=hidden VALUE="">|
Forall varMatch In varMatches
'Create a radio button for this match
Print |<INPUT TYPE=radio NAME="SelectUser" VALUE="| & varMatch & |" onClick="Temp.value='| & varMatch & |'">| & varMatch & |<br>|
End Forall
'Create the OK and Cancel buttons
Print |<BR><DIV ALIGN=center><INPUT TYPE=button onClick="addNames()" VALUE="OK">|
Print |<INPUT TYPE=button onClick="window.close()" VALUE="Cancel"><DIV>|
End If
End If
If Not(bFound) Then
'No matches found. Just create a message and a Close button.
If strSearchFor = "" Then
Print "Please enter a name to search for. <br>"
Else
Print "Search for users with name containg the word - " & strSearchFor & " - did not find any matches. <br>"
End If
Print |<BR><DIV ALIGN=center><INPUT TYPE=button onClick="window.close()" VALUE="Close"></DIV>|
End If
Exit Sub
ErrorHandler:
Print "Error " & Str(Err) & ": " & Error$
End Sub 'agtNamePickerS
 |
 |  |
|