Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LS Agent arror looping address book

Status
Not open for further replies.

DoctorGonzo

Programmer
Jan 23, 2004
48
0
0
GB
Hi all,

Could do with some advice.... I have an agent that is generating an "ILLEGAL USE OF PROPERTY" error in the log.

Basically I want to loop through my "profile" database and for each document, check if a PERSON document exists in the address book. If it does, I want to replace the multi value field USERNAME on my user form in the PROFILE db with the FULLNAME field on the person document in the NAB. the USERNAME field is a NAMES field, but the FULLNAME field in the NAB is a text list.... does anyone have any ideas what I'm doing wrong, or a better way to do this?

Here is the agent....

Sub Initialize
' define my objects
Dim session As New notessession
Dim db As notesdatabase, servernab As notesdatabase
Dim view As notesview
Dim nabview As notesview
Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
Dim profdoc As notesdocument, nabdoc As notesdocument
Dim username, mvField() As String
Dim no As Integer

'profile (this) database...
Set db = session.currentdatabase

'NAB database....
Set servernab = session.getdatabase(db.server,"names.nsf")

If servernab.isopen Then
' get views containing hierarchical names...
'view in NAB...
Set nabview = servernab.getview("($VIMPeople)")

'view in other database...
Set view = db.getview("Profiles")

' loop through PROFILE Database checking names against NAB
' get profile view containing hierarchical names... values as seperate entires

Set doc = view.getfirstdocument

Do While Not(doc Is Nothing)
' lookup to NAB uses the ABBREVIATED version of username on form
username = doc.abUsername(0)
Set nabdoc = nabview.getdocumentbykey(username,True)
Set olddoc = view.getnextdocument(doc)

If Not(nabdoc Is Nothing) Then
no = Ubound(nabdoc.FullName)
Redim mvField(no)
For i = 0 To no
mvField(i) = nabdoc.FullName(i)
doc.username(i) = nabdoc.FullName(i)
Next

End If
Set doc = olddoc
Loop


End If
End Sub
 
doc.username(i) = nabdoc.FullName(i) is most likely the error, trying to allocate non-existing elements in an array (variant)

Maybe a better method:
...
If Not(nabdoc Is Nothing) Then
Dim usernames as variant
usernames = doc.username
no = Ubound(nabdoc.FullName)
Redim mvField(no)
For i = 0 To no
mvField(i) = nabdoc.FullName(i)
if (usernames(0) = "") then
usernames(0) = nabdoc.FullName(i)
else
usernames = arrayappend(usernames, nabdoc.FullName(i))
end if
Next
doc.username = usernames
End If
Set ...




Brgds,

TrooDOS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top