Script to Add Email Forwards (Import Text & Arrays)

note: we are testing on a V7 server but are about to upgrade and run this on a V8 server. Posted this on the V7 forum but thought I might include on the V8 forum just in case. Thanks team…

FYI: the import file is comma-delimited and each line represents a different user. See below…

user1@test.com,user1@new.test.com

user2@test.com,user2@new.test.com

The first value is the current email (internetaddress field) and will be used to find the unique person document. The 2nd value is the address to be added to the email forward field (mailaddress). The values are separated by a comma.

I have been working on this over the weekend… with limited success. What am I missing here? FYI… my original posting was a bit incorrect. It is not old email address to new email address (as in same field… internetaddress). The old email would be used for the lookup <per previous posting - is in the internetaddress field> and the 2nd or new email address would be added to the mailaddress or forwarding address field.

Here is my script so far:

note: the script debugger is complaining about a couple things. #1 is my “Set counter = 0”… complains about using set. #2 is the “doc.MailAddress = newmail( count )”… complains about an illegal parenthesized reference. If I remove the set and the ( count ) , the script will run to a point. I’m getting a “input past end of file” dialog right after entering in file location. My print statement says it stops at the “Input #fileNum%, arrayOfRecs(countrec%).oldmail, _arrayOfRecs(countrec%).newmail” line. Am I close? Honestly, I am confused about the array (is is correct?). I tried to test this same method with a simple search for oldmail value… used the print statement to let me know if no such value or value found. This worked… reason for my feeling somewhat confident re: arrays.

Declaration:

Type MailType

oldmail As Variant

newmail As Variant

End Type

Sub Click(Source As Button)

'PURPOSE: set the names of the admin server and directory

Dim server As String

Dim database As String

server=“testserver/test”

database=“testdir.nsf”

'PURPOSE: set the correct admin server and directory

Set db = New NotesDatabase( server, database )

Set view = db.GetView( “$VIMPeople” )

'PURPOSE: start at first document in the $VIMPeople view

Dim count As Integer

Set doc = view.getFirstDocument

Set count = 0

'PURPOSE: open comma-delimited text file and create variant arrays

Dim arrayOfRecs() As MailType

Dim txt As String

Dim fileNum As Integer

Dim counter As Integer

Dim countRec As Integer

Dim found As Boolean

fileNum% = Freefile ’ Get a file number to open a file.

counter% = 0

file = Inputbox$(“Where is your import file located?”)

Open file For Input As fileNum%

Do While Not Eof(fileNum%)

Line Input #fileNum%, txt$ ’ Read each line of the file.

counter% = counter% + 1 ’ Increment the line count.

Loop

Seek fileNum%, 1 ’ Pointer to beginning of file

’ Since file has counter% number of lines, define arrayOfRecs ’ to have that number of elements.

Redim arrayOfRecs(1 To counter%)

’ Read the file contents into arrayOfRecs.

For countRec% = 1 To counter%

Input #fileNum%, arrayOfRecs(countrec%).oldmail, _

arrayOfRecs(countrec%).newmail( count )

Next

Close fileNum%

'PURPOSE: process person documents using oldmail array to locate

'person document and newmail array to populate forwarding address

While Not(doc Is Nothing)

Forall v In oldmail

'PURPOSE: check each value in the array for a match.

If doc.InternetAddress(0) = v Then

'PURPOSE: access each person document and update the email forwarding address

doc.MailAddress = newmail

Call doc.Save( True, False )

End If

count = count + 1

End Forall

count = 0

Set doc = view.GetNextdocument( doc )

Wend

End Sub