Link to home
Start Free TrialLog in
Avatar of androgyny7
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.GetDocumentByKey(kwdName, True)
            If kwdDoc Is Nothing Then
                  s_getKeywordValues = Null
            Else
                  Set kwdItem = kwdDoc.GetFirstItem("KeywordList")
                  If kwdItem Is Nothing Then
                        s_getKeywordValues = Null
                  Else
                        s_getKeywordValues = kwdItem.Values
                  End If
            End If
      End If
End Function
Avatar of mbonaci
mbonaci
Flag of Croatia image

Hi androgyny7,
To process all values of SendTo field instead of this:

    Set nam = New NotesName(doc.GetItemValue("SendTo")(0))
    address = nam.Abbreviated
    addresses = s_getKeywordValues(address)

use something like this:

    For i = 0 to Ubound( doc.SendTo )
        Set nam = New NotesName(doc.GetItemValue("SendTo")(i))
        address = nam.Abbreviated
        addresses = ArrayAppend( addresses, s_getKeywordValues( address ) )
    Next


Hope this helps,
Marko
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
Avatar of androgyny7
androgyny7

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
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.
ASKER CERTIFIED SOLUTION
Avatar of mbonaci
mbonaci
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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