androgyny7
asked on
Dynamic array?? Or is that not the best way?
Hi. Trying to create an agent that will forward emails to specific replica's of another inbox dependant on a time zone. The email will be forwarded to addresses set up in the keywords view. However what I need to be able to do is capture multiple addresses in the sendto field and multiple addresses in the CC field. Each address has to be compared to the keyword view and then a new address is assigned to the email. The code below will work for just one address in the Sendto field.
While Not(doc Is Nothing)
Set docb = view.GetNextDocument(doc)
Set item = doc.GetFirstItem( "PostedDate" )
Set dateTime = item.DateTimeValue
zone = dateTime.TimeZone
Select Case zone
Case -3, -2, -1, 0, 1, 2, 3, 4, 5
Place = "EU"
Case -11, -10, -9, -8, -7, -6, -5, -4
Place = "NA"
Case 6, 7, 8, 9, 10, 11, 12, -12
Place = "AP"
End Select
Set nam = New NotesName(doc.GetItemValue ("SendTo") (0))
address = nam.Abbreviated
addresses = s_getKeywordValues(address )
Forall x In addresses
contains = Instr(1, x, Place)
If contains > 0 Then
forwardaddress = s_Right(x, Place)
End If
End Forall
Set forwarddoc = New NotesDocument(db)
Call doc.CopyAllItems( forwarddoc, True )
forwarddoc.principal = doc.from(0)
forwarddoc.SendTo = forwardaddress
Call forwarddoc.Send( False )
doc.Processed = "Yes"
Call doc.Save(True, True)
Set doc = docb
Wend
The function s_getkeywordvalues does:
Function s_getKeywordValues( kwdName As String) As Variant
Dim kwdDoc As notesDocument
Dim kwdItem As NotesItem
If g_kwSysView Is Nothing Then
s_getKeywordValues = Null
Else
Set kwdDoc = g_kwSysView.GetDocumentByK ey(kwdName , True)
If kwdDoc Is Nothing Then
s_getKeywordValues = Null
Else
Set kwdItem = kwdDoc.GetFirstItem("Keywo rdList")
If kwdItem Is Nothing Then
s_getKeywordValues = Null
Else
s_getKeywordValues = kwdItem.Values
End If
End If
End If
End Function
While Not(doc Is Nothing)
Set docb = view.GetNextDocument(doc)
Set item = doc.GetFirstItem( "PostedDate" )
Set dateTime = item.DateTimeValue
zone = dateTime.TimeZone
Select Case zone
Case -3, -2, -1, 0, 1, 2, 3, 4, 5
Place = "EU"
Case -11, -10, -9, -8, -7, -6, -5, -4
Place = "NA"
Case 6, 7, 8, 9, 10, 11, 12, -12
Place = "AP"
End Select
Set nam = New NotesName(doc.GetItemValue
address = nam.Abbreviated
addresses = s_getKeywordValues(address
Forall x In addresses
contains = Instr(1, x, Place)
If contains > 0 Then
forwardaddress = s_Right(x, Place)
End If
End Forall
Set forwarddoc = New NotesDocument(db)
Call doc.CopyAllItems( forwarddoc, True )
forwarddoc.principal = doc.from(0)
forwarddoc.SendTo = forwardaddress
Call forwarddoc.Send( False )
doc.Processed = "Yes"
Call doc.Save(True, True)
Set doc = docb
Wend
The function s_getkeywordvalues does:
Function s_getKeywordValues( kwdName As String) As Variant
Dim kwdDoc As notesDocument
Dim kwdItem As NotesItem
If g_kwSysView Is Nothing Then
s_getKeywordValues = Null
Else
Set kwdDoc = g_kwSysView.GetDocumentByK
If kwdDoc Is Nothing Then
s_getKeywordValues = Null
Else
Set kwdItem = kwdDoc.GetFirstItem("Keywo
If kwdItem Is Nothing Then
s_getKeywordValues = Null
Else
s_getKeywordValues = kwdItem.Values
End If
End If
End If
End Function
androgyny7,
I suggest you to use Option Declare in your designe element's Globals - Options to force you to declare all variables.
You can make it default for all new design elements by using option "Automatically add Option Declare" in the Programmer pane properties, second tab.
It'll save you great deal of time.
Marko
I suggest you to use Option Declare in your designe element's Globals - Options to force you to declare all variables.
You can make it default for all new design elements by using option "Automatically add Option Declare" in the Programmer pane properties, second tab.
It'll save you great deal of time.
Marko
ASKER
Hi! Thanks for your comments - the issue is that sometimes the s_getkeywordvalues isn't going to return anything and so will errror when you try to append it to an array.
androgyny7,
Dim tmpAddr, address, addresses '(this is the same as you declared each of them As Variant)
For i = 0 to Ubound( doc.SendTo )
Set nam = New NotesName(doc.GetItemValue ("SendTo") (i))
address = nam.Abbreviated
tmpAddr = s_getKeywordValues( address )
If Not tmpAddr = Null Then
addresses = ArrayAppend( addresses, tmpAddr )
End If
Next
Hope this helps,
Marko
Dim tmpAddr, address, addresses '(this is the same as you declared each of them As Variant)
For i = 0 to Ubound( doc.SendTo )
Set nam = New NotesName(doc.GetItemValue
address = nam.Abbreviated
tmpAddr = s_getKeywordValues( address )
If Not tmpAddr = Null Then
addresses = ArrayAppend( addresses, tmpAddr )
End If
Next
Hope this helps,
Marko
ASKER
I had something similar in my code:
For i = 0 To Ubound( doc.SendTo )
Set nam = New NotesName(doc.GetItemValue ("SendTo") (i))
address = nam.Abbreviated
addresslookup = s_getKeywordValues(address )
If addresslookup <> Null Then
Forall x In addresslookup
contains = Instr(1, x, Place)
If contains > 0 Then
forwardaddress = s_Right(x, Place)
End If
End Forall
addresses = Arrayappend( addresses, forwardaddress )
End If
Next
The problem is that if s_getkeywordvalues returns a value it will contain at least 1 value, most likely 3. And so I get a type mismatch errror.
For i = 0 To Ubound( doc.SendTo )
Set nam = New NotesName(doc.GetItemValue
address = nam.Abbreviated
addresslookup = s_getKeywordValues(address
If addresslookup <> Null Then
Forall x In addresslookup
contains = Instr(1, x, Place)
If contains > 0 Then
forwardaddress = s_Right(x, Place)
End If
End Forall
addresses = Arrayappend( addresses, forwardaddress )
End If
Next
The problem is that if s_getkeywordvalues returns a value it will contain at least 1 value, most likely 3. And so I get a type mismatch errror.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the code fails on the If addresslookup <> Null Then statement. It doesnt even go into the Forall loop.
androgyny7,
try like this:
If Not IsNull( addresslookup ) Then
Hope this helps,
Marko
try like this:
If Not IsNull( addresslookup ) Then
Hope this helps,
Marko
androgyny7,
and if there's a posibility to returned data can be "" Then include IsEmpty, like this (cuz' IsEmpty can be False and IsNull True of the same variant variable - see help for details):
If Not IsNull( addresslookup ) Then
If Not IsEmpty( addresslookup ) Then
Hope this helps,
Marko
and if there's a posibility to returned data can be "" Then include IsEmpty, like this (cuz' IsEmpty can be False and IsNull True of the same variant variable - see help for details):
If Not IsNull( addresslookup ) Then
If Not IsEmpty( addresslookup ) Then
Hope this helps,
Marko
To process all values of SendTo field instead of this:
Set nam = New NotesName(doc.GetItemValue
address = nam.Abbreviated
addresses = s_getKeywordValues(address
use something like this:
For i = 0 to Ubound( doc.SendTo )
Set nam = New NotesName(doc.GetItemValue
address = nam.Abbreviated
addresses = ArrayAppend( addresses, s_getKeywordValues( address ) )
Next
Hope this helps,
Marko