Web Address Lookup ---Again (I know it's been done before but...)

Ok, I’ve read through hundreds of posts, tried 4 different solutions from ‘the view’ from here, from sandbox from the web, from all over, and I still can’t get the damn thing to work right.

I’ve got a form that people will access via IE6, when the users are done filling out the form, there’s a place for them to address it and send it out. The form, in essense, is a meeting invitation.

When this was strictly a notes app, doing an address book dialog box for the SendTo field was a piece of cake, it worked without a hitch. Now that it needs to be web-enabled…I can’t get the dang thing to work.

I need to be able to pull up the People and/or the Groups entries from our PNAB and allow the user to choose the attendees. These can be seperate pulls, that’s not a problem. Currently our PNAB has 170,000 documents in the people view and over 35,000 documents in the groups view. So I exceed the 64K limit and the 1000 record limit for some of the solutions I’ve seen.

Most of the past two days I’ve been trying to implement the solution by Sunilkumar Vishwakarma that uses an agent called from a button. My Javascript is weak, I’ll be honest, but I followed all the instructions on how to install this solution and got back a variety of weird errors. Here’s the start of the instructions:

Please note that DBPath is a Computed For Display field on the form from where you wish to call the Web Address Book. The formula for DBPath field is

@ReplaceSubstring(@Subset(@DbName;-1);“\”;“/”)

Also, please note that screenWidth and screenHeight are variables to be defined in the JavaScript header section, as written below: (Note: screenWidth and screenHeight are used in openAddressDialogbox().)

var screenWidth = screen.width;

var screenHeight = screen.height;

Here’s the code for the AddressBook:

Javascript:


how to call:

openAddressDialogbox(document.forms[0].fieldName)

function openAddressDialogbox(element) {

window.nameElement = element ;

var popUpWidth = 342;

var popUpHeight = 400;

var popUpLeft = parseInt((screenWidth - popUpWidth)/2);

var popUpTop = parseInt((screenHeight - popUpHeight)/2);

var strNewWin = ‘/’ + document.forms[0].DbPath.value

  • ‘/agtWebNAB?OpenAgent&default=’ + escape(element.value);

//alert(strNewWin);

var newWin = window.open( strNewWin , ‘newWin’,

'toolbar=no,location=no,directories=no,

status=yes,resizable=no,scrollbars=no,menubar=no,top='+popUpTop

+‘,left=’+popUpLeft+‘,width=’+popUpWidth+‘,height=’+popUpHeight );

}

and the error I’m getting is that document.forms[0].DbPath.value is null or not an object

Has anyone attempted this solution? Do you know if the DBPath field needs to be Passthru HTML? Do I need to store the form in the document, do I need to call a save of some sort before I call the agent? Any suggestions or pointers would be welcome. At this point, Im’ getting desperate, and 3 days past my deadline isn’t helping if you know what I mean.

Thanks in advance,

Wes

Subject: Web Address Lookup —Again (I know it’s been done before but…)

You DbPath field needs to be an editable field visible to the browser to be readable from javascript. You can add type=“hidden” in the other field of the tab in field properties to hide it.

You can also do this:

var strNewWin = new String(location.href.slice(0, location.href.toLowerCase().indexOf(‘.nsf’)+4));

(this takes everything from the current location, to the left of the .nsf part )

Subject: RE: Web Address Lookup —Again (I know it’s been done before but…)

Fantastic! That worked …but only so far in that the pop up window opened. I got another error message, the common “HTTP 500 Internal Server Error” Page cannot be Displayed.

So far, this part of the code now works (thanks to Bjorn):

openAddressDialogbox(document.forms[0].DBPath)

function openAddressDialogbox(element) {

window.nameElement = element ;

var popUpWidth = 342;

var popUpHeight = 400;

var popUpLeft = parseInt((screenWidth - popUpWidth)/2);

var popUpTop = parseInt((screenHeight - popUpHeight)/2);

var strNewWin = ‘/’ + document.forms[0].DBPath.value + ‘/agtWebNAB?OpenAgent&default=’ + escape(element.value);

//alert(strNewWin);

var newWin = window.open( strNewWin , ‘newWin’, ‘toolbar=no,location=no,directories=no,status=yes,resizable=no,scrollbars=no,menubar=no,top=’+popUpTop+‘,left=’+popUpLeft+‘,width=’+popUpWidth+‘,height=’+popUpHeight );

}

You can see from the code that the popup window is calling the agtWebNAB?OpenAgent

The agent looks like this (it’s long, sorry, I’ll post my questions below the agent code at the bottom of this page, thanks for reading this far)

Sub Initialize

On Error Goto errorHandler

’ start printing the HTML

Print | <HTML><HEAD>
Address Book

|

’ print the styles to be used

Print | 
BODY { font-family: verdana,arial,helvetica; font-size: 8pt; margin: 4 ; background: #EFEFEF; } INPUT, SELECT { font-family: verdana,arial,helvetica; font-size: 8pt; border-style: solid; border-color: #000000; border-width: 1; } TABLE { border-width: 0; } TD { background: #FFFFFF; color: #000000; font-family: verdana,arial,helvetica; font-size: 8pt; font-weight: normal; text-align: left ; vertical-align: top ; padding: 2; border-width: 0; } .BLUE { background: #C0E1FF; border-style: solid; border-color: #4181C0; border-width: 1; } .GREY { background: #EFEFEF; border-style: solid; border-color: #808080; border-width: 1; } .LIST { width: 322 ; } .ODD { background: #FFFFFF;} .EVEN { background: #C0E1FF;} .GROUP { background-color: #F1F1B4; border: 2 solid #808080 } .BUTTONB { background: #C0E1FF; border-style: solid; border-color: #4181C0; border-width: 1; cursor: hand ; } .BUTTONG { background: #D0D0D0; border-style: solid; border-color: #000000; border-width: 1; cursor: hand ; }

|

’ print disable right click JavaScript Code

Print |

|

’ print the JavaScript functions called in the buttons

Print |<SCRIPT LANGUAGE=JavaScript>
|

’ code to populate options starts

Dim session As NotesSession

Dim db As NotesDatabase

Dim ndb As NotesDatabase



Dim books As Variant

Dim selectedBook As String



Dim docContext As NotesDocument

Dim vw As NotesView

Dim nav As NotesViewNavigator

Dim entry As NotesViewEntry



Set session = New NotesSession

Set docContext = session.DocumentContext

books = session.AddressBooks



Dim h_QueryString_Decoded As String

h_QueryString_Decoded = Cstr(docContext.Query_String_Decoded(0))



Dim strNdbServer As String



strNdbServer = extractParameter(h_QueryString_Decoded,"addressBook")

’ start printing the BODY

Print "<BODY OnContextMenu='return false'>"

Print "<FORM Name='form1' method='POST' action=''>"



Print "<TABLE CELLSPACING=3 CELLPADDING=0>" 



Print |
Look in Address Book(s)

|

Set db = session.CurrentDatabase 

'Print “”

Dim namServer As NotesName 



If strNdbServer = "" Then

’ get names.nsf database on current server

	Set ndb = session.getDatabase("","names")

Else

‘’ get names.nsf database on selected server

	Set ndb = session.getDatabase(strNdbServer,"names") 

End If



Set namServer = New NotesName(ndb.Server) 

'Continue Printing

Print "<TR VALIGN=top><TD CLASS=BLUE WIDTH=322><DIV ALIGN=center><B>Names on " & namServer.Common & "</B></DIV></TD></TR>"

Print "<TR VALIGN=top><TD CLASS=GREY WIDTH=322><DIV ALIGN=center>"



If Not ndb.IsOpen Then

	Call ndb.Open("","names")

End If

’ get the People view and create a ViewNavigator object for navigating the entries in the view

Set vw = ndb.getView("$VIMPeopleAndGroups")

Set nav = vw.createViewNav()

’ get the first document in view

Set entry = nav.getFirstDocument()

’ initialize variables required later on

Dim pos As Integer

Dim maxCount As Integer

Dim l_first As String

Dim l_prev As String

Dim l_next As String

Dim l_last As String

Dim l_search As String

’ variable for maximum names to be shown as options in the SELECT tag

maxCount = 200

’ variable for the actions passed in the URL

l_first = "first"

l_prev = "prev"

l_next = "next"

l_last = "last"

l_search = "search"



Dim defaultSelection As String

Dim startParameter As String

Dim start As Integer

Dim action As String

’ gets the default value for selection passed in the URL

defaultSelection = extractParameter(h_QueryString_Decoded,"default")

’ gets the start parameter passed in the URL

startParameter = extractParameter(h_QueryString_Decoded,"start")

start = 1

If Isnull(startParameter) Or startParameter="" Then

	start = 1

	pos = 1

Else 

	start = startParameter

	pos = start

End If

’ Gets the button clicked on the window

action = extractParameter(h_QueryString_Decoded,"act")



If Isnull(action) Then

’ Keep the entry as first document

Elseif action=l_first Then

’ Keep the entry as first document

Elseif action=l_prev Then

	pos = start - maxCount

	If pos<1 Then

		pos=1

	End If

	Set entry = nav.getNth(pos)

	If entry Is Nothing Then

		Set entry = nav.getFirstDocument()

	End If

Elseif action=l_search Then

	Set entry = vw.getEntryByKey(extractParameter(h_QueryString_Decoded,"query"), False)

	If entry Is Nothing Then

		pos = start

	Else

		pos = entry.getPosition(".")

	End If

	Set entry = nav.getNth(pos)

Elseif action=l_next Then

	pos = start + maxCount

	Set entry = nav.getNth(pos)

	If entry Is Nothing Then

		Set entry = nav.getLastDocument()

		pos = entry.getPosition(".")

	End If

Elseif action=l_last Then

	Set entry = nav.getLastDocument()

	pos = entry.getPosition(".")

	pos = pos - maxCount + 1

	If pos < 1 Then

		pos = 1

	End If

	Set entry = nav.getNth(pos)

Else 

’ Keep the entry as first document

End If



Dim varTemp As Variant

varTemp = Evaluate(|@Left("| & h_QueryString_Decoded & |";"OpenAgent") + "?OpenAgent"|)

’ print the navigation buttons

Print "<INPUT TYPE=hidden NAME='hAgentContext' VALUE='" & varTemp(0) & "'>"

Print |<INPUT TYPE=button VALUE=First CLASS='BUTTONB' onClick=clickFirst(| & pos & |) onmouseover="this.className='BUTTONG'" onmouseout="this.className='BUTTONB'" >|

Print |<INPUT TYPE=button VALUE=Prev CLASS='BUTTONB' onClick=clickPrev(| & pos & |) onmouseover="this.className='BUTTONG'" onmouseout="this.className='BUTTONB'" >|

Print |<INPUT NAME=SearchString VALUE='' SIZE=12 MAXLENGTH=10 TITLE="Type search query and click 'Go' button">|

Print |<INPUT TYPE=button VALUE=Go CLASS='BUTTONB' STYLE='width:30' onClick=clickSearch(| & pos & |) onmouseover="this.className='BUTTONG'" onmouseout="this.className='BUTTONB'" >|

Print |<INPUT TYPE=button VALUE=Next CLASS='BUTTONB' onClick=clickNext(| & pos & |) onmouseover="this.className='BUTTONG'" onmouseout="this.className='BUTTONB'" >|

Print |<INPUT TYPE=button VALUE=Last CLASS='BUTTONB' onClick=clickLast(| & pos & |) onmouseover="this.className='BUTTONG'" onmouseout="this.className='BUTTONB'" >|



Print "</DIV></TD></TR>"

Print "<TR VALIGN=top><TD CLASS=GREY WIDTH=300><SELECT NAME=AddressList SIZE=15 CLASS=LIST onClick=popName() onChange=popName()>"



Dim count As Integer

’ initializes the counter

count = 0

’ iterate through the view entries till end of view or maximum count in the options list is reached

Dim eType As String

Dim vFieldName As String

Dim person As NotesName



While (Not entry Is Nothing And (count<maxCount))

	eType = entry.document.getItemValue("Type")(0)

	

	If eType = "Person" Then

		vFieldName = "FullName"

	Else

		vFieldName = "ListName"

	End If

’ creates a Name object for getting username in abbreviated format

	Set person = session.CreateName(entry.document.getItemValue(vFieldName)(0))

	

	If eType = "Person" Then

		If count Mod 2 = 0 Then

			Print "<OPTION CLASS='EVEN' VALUE='" & person.Common & "' TITLE='" & person.Abbreviated & "'>" & person.Common & "</OPTION>"

		Else

			Print "<OPTION CLASS='ODD' VALUE='" & person.Common & "' TITLE='" & person.Abbreviated & "'>" & person.Common & "</OPTION>" 

		End If

	Else

		Print "<OPTION CLASS='GROUP' VALUE='" & person.Common & "' TITLE='" & person.Abbreviated & "'>[ " & person.Common & " ]</OPTION>" 

	End If

	

	count = count + 1

’ get the next view entry

	Set entry = nav.getNextDocument(entry)

Wend



Print "</SELECT></TD></TR>"

Print "<TR VALIGN=top><TD CLASS=BLUE WIDTH=322><B>></B> "

Print "<INPUT NAME=Selection VALUE='" & defaultSelection & "' size=45 READONLY STYLE='background: #C0E1FF; border-width: 0;'></TD></TR>"

Print "<TR VALIGN=middle><TD CLASS=GREY WIDTH=322><DIV ALIGN=center>"

Print |<INPUT TYPE=button VALUE='OK' CLASS='BUTTONB' STYLE='width: 50' onClick='window.opener.nameElement.value = document.forms[0].Selection.value ; window.close()' onmouseover="this.className='BUTTONG'" onmouseout="this.className='BUTTONB'" >|

Print |<INPUT TYPE=button VALUE='Cancel' CLASS='BUTTONB' STYLE='width: 50' onClick='self.close()' onmouseover="this.className='BUTTONG'" onmouseout="this.className='BUTTONB'" ></DIV>|

Print "</TD></TR>"



Print |
*Entries in this color are GROUPS enclosed by [ ]

|

Print "</TABLE>"

’ finish off the code

’ end of the HTML

Print "</FORM></BODY></HTML>" 

Exit Sub

errorHandler:

Msgbox "[ApplicationName] : Error in " & "agtWebNAB" & " at line number " & Erl

Msgbox "[ApplicationName] : Error Number is " & Err

Msgbox "[ApplicationName] : Error Description is " & Error

End Sub

Public Function ExtractParameter ( QueryString As String, ParameterName As String) As String

On Error Goto errorHandler



ParameterName = ParameterName & "="

Dim startPosition, endPosition, queryStringLength, parameterLength As Integer

Dim parameterValue As String



queryStringLength = Len ( QueryString )

parameterLength = Len ( ParameterName )

startPosition = Instr ( 1, QueryString, ParameterName, 5 )



If startPosition = 0 Then

	parameterValue = ""

Else

	

	startPosition = startPosition + parameterLength

	endPosition= Instr ( startPosition, QueryString, "&" )

	

	If ( endPosition = 0 ) Then

		endPosition = queryStringLength + 1

		parameterLength = endPosition - startPosition

		parameterValue = Mid ( QueryString, startPosition,parameterLength )

	Elseif ( endPosition <> 0 ) Then

		parameterLength = endPosition - startPosition

		parameterValue = Mid ( QueryString, startPosition,parameterLength )

	End If

	

End If



ExtractParameter = parameterValue

Exit Function

errorHandler:

Msgbox "[ApplicationName] : Error in " & "ExtractParameter()" & " at line number " & Erl

Msgbox "[ApplicationName] : Error Number is " & Err

Msgbox "[ApplicationName] : Error Description is " & Error 

End Function

My thought is that this code probably works fine. Because of the Page Cannot Be Displayed error, I’m more likely missing a setting or a call somewhere. The script didn’t kick out any errors in the debugging process, and this solution has been floating around the web for a while so I’m more inclined to believe the code is solid.

Why would this agent not be able to open the popup in a new window? Is there a popup setting I’m missing? Could it be a browser setting or a notes setting? Thanks in advance for the help!

Wes

Subject: Web Address Lookup —Again (I know it’s been done before but…)

There is a view named “People” in the Address Book db. I think the 3rd or the 4th column has the address of the employees. Use dbcolumn to get the mail address, that works in web.

  To get the web ids, press Ctrl + Shift then goto to get to a manually hidden view ($NamesFieldLookup) . Dbcolumn the first column. It will have double values. Omit the ones without @compname. Hope this works.

Subject: Web Address Lookup —Again (I know it’s been done before but…)

I may be biased but my personal favorite for a web nab picker can be found in a post on this blog site (sorry can’t give you a specific address - I can’t access the site from my current client):

http://www.scottgood.com

Scott went through a bit of work tweaking the solution to make sure it looks and functions as close as possible to the NAB picker included in Notes. It’s easy to implement and runs fast even on large address books.

Subject: RE: Web Address Lookup —Again (I know it’s been done before but…)

Scott’s site is full of amazing tips and tricks, I just spent two hours reading through his place. I haven’t found the script yet for the NAB over the web but dang! this is a treasure chest of really cool stuff! If you could find the link to the Web NAB info lateron when your not at your client site and post it back here for me that’d be great, thanks. Until then I’m going to keep hunting around this site. I already see two things I’m gonna try to implement as well, great tips!

Wes

Subject: RE: Web Address Lookup —Again (I know it’s been done before but…)

http://www.scottgood.com/jsg/blog.nsf/d6plinks/SGOD-6HXQHF

Subject: RE: Web Address Lookup —Again (I know it’s been done before but…)

I like the implementation Jake did at http://www.codestore.net/store.nsf/sandbox/