/ Forums / Advansys Formativ / Creating Solutions with Formativ / Handling multiple attachments

  • Creator
    Topic
  • #4337
    LuAnn
    Participant

      We are trying to use a GroupWise address book for a mass mailing, similar to the “Quick Send” applet. Instead of using a text file, we want to use a field from the Addressbook/contacts folder.

      The applet works fine for a single attachment, but not for multiple attachments.

      We’re using the trial version of Formativ Studio (purchasing is underway with a US vendor) and GroupWise 7.0.

      Here’s the script:

      Sub Main(Client, GWEvent)

      Dim objAddressBooks
      Dim objAddessBook
      Dim objAddressBookEntry
      Dim objSubject
      Dim objMessage
      Dim objMsg
      Dim objAttach
      Dim objAttachs
      Dim iAttachCounter
      Dim iMsgID

      Set objMsg = GroupWise.ComposingItem
      objSubject = objMsg.Subject
      objMessage = objMsg.BodyText

      ‘ Get the composing message ID through TOKEN
      iMsgID = GroupWise.ItemMessageIDFromView
      ‘ Make sure we have a composing message selected
      iAttachCounter = GroupWise.ItemAttachmentGetCount(iMsgID)
      if (iAttachCounter > 0) then
      for x = 0 to (iAttachCounter -1)
      objAttach = GroupWise.ItemAttachmentGetName(iMsgID, x)
      msgBox(objAttach)
      next
      end if
      ‘ Get the AddressBooks object
      Set objAddressBooks = GroupWise.Account.AddressBooks
      ‘ Locate the address book called ‘Address Book’

      Set objAddressBook = objAddressBooks.Item(“Contacts for Newsletter”)

      ‘ Display the email address of each entry in the book

      For Each objAddressBookEntry In objAddressBook.AddressBookEntries
      if objAddressBookEntry.emailaddress <> “” Then
      ‘ Create new mail message
      Call GroupWise.NewMail
      ‘ Enter the recipient
      Call GroupWise.FocusSet(fcsTo, “”)
      Call GroupWise.TypeText(objAddressBookEntry.emailaddress)

      ‘ Enter the subject
      Call GroupWise.FocusSet(fcsSubject, “”)
      Call GroupWise.TypeText(objSubject)
      ‘ Enter the message body, first insert the greeting from contact comment field
      ‘ after that enter the text as type in the previous window
      Call GroupWise.FocusSet(fcsMessage, “”)

      Call GroupWise.TypeText(objMessage)
      ‘ Add attachment if any
      if (iAttachCounter > 0) then
      ‘ Loop through attachments to get the names
      for x = 0 to (iAttachCounter -1)

      call GroupWise.ItemAttachmentAdd(“X00”, itcAttachClassFile, objAttach, “”)

      next
      end if

      ‘ Send the message
      Call GroupWise.ItemSend(False)
      Utilities.doevents
      end if
      next

      Set objAddressBook = Nothing
      Set objAddressBooks = Nothing
      Set objMsg = Nothing

      End Sub

    • Author
      Replies
    • #7853
      Support 3
      Participant

        Your sample code has a logical error. See below the section of your code which only add the one attachment to the new message as the value of the objAttach never change.

        quote:


        ‘ Loop through attachments to get the names
        for x = 0 to (iAttachCounter -1)
        call GroupWise.ItemAttachmentAdd(“X00”, itcAttachClassFile, objAttach, “”)
        next


        You can use a stringlist to store the attachments from the draft message and finally add to the new message. See below the updated source code.

          
        Sub Main(Client, GWEvent)
        
        Dim objAddressBooks
        Dim objAddessBook
        Dim objAddressBookEntry
        Dim objSubject
        Dim objMessage
        Dim objMsg
        Dim objAttach
        Dim objAttachs
        Dim iAttachCounter
        Dim iMsgID
        
        dim oAttachmentsList
        
        Set objMsg = GroupWise.ComposingItem
        objSubject = objMsg.Subject
        objMessage = objMsg.BodyText
        
        ' Get the composing message ID through TOKEN
        iMsgID = GroupWise.ItemMessageIDFromView
        ' Make sure we have a composing message selected
        iAttachCounter = GroupWise.ItemAttachmentGetCount(iMsgID)
        
        
        '** Create a strings list and store the available attachments from the draft message **
        set oAttachmentsList = utilities.stringlist
        if (iAttachCounter > 0) then
          for x = 0 to (iAttachCounter -1)
            objAttach = GroupWise.ItemAttachmentGetName(iMsgID, x)
            oAttachmentsList.add(objAttach)
          next
        end if
        
        
        ' Get the AddressBooks object
        Set objAddressBooks = GroupWise.Account.AddressBooks
        ' Locate the address book called 'Address Book'
        
        Set objAddressBook = objAddressBooks.Item("Test Book")
        
        ' Display the email address of each entry in the book
        
        For Each objAddressBookEntry In objAddressBook.AddressBookEntries
          if objAddressBookEntry.emailaddress <> "" Then
            ' Create new mail message
            Call GroupWise.NewMail
        
            ' Enter the recipient
            Call GroupWise.FocusSet(fcsTo, "")
            Call GroupWise.TypeText(objAddressBookEntry.emailaddress)
        
            ' Enter the subject
            Call GroupWise.FocusSet(fcsSubject, "")
            Call GroupWise.TypeText(objSubject)
        
            ' Enter the message body, first insert the greeting from contact comment field
            ' after that enter the text as type in the previous window
            Call GroupWise.FocusSet(fcsMessage, "")
        
            Call GroupWise.TypeText(objMessage)
            ' Add attachment if any
            if (iAttachCounter > 0) then
        
              ' Loop through attachments list and add to the new message
              for x = 0 to (oAttachmentsList.count -1)
                call GroupWise.ItemAttachmentAdd("X00", itcAttachClassFile, oAttachmentsList.strings(x), "")
              next
        
            end if
        
           ' Send the message
           Call GroupWise.ItemSend(False)
           Utilities.doevents
          end if
        next
        
        Set objAddressBook = Nothing
        Set objAddressBooks = Nothing
        Set objMsg = Nothing
        
        set oAttachmentsList = nothing
        
        End Sub
        

        Regards,
        Advansys Support

        #7854
        LuAnn
        Participant

          Thank you for the prompt response!

          I’m actually communicating FOR our developer, so the next question is:

          The developer found the error and handled it in a different manner. I’ve cut and pasted the script below. Are there any inherent dangers in THIS script?

          ——————————————————————————-
          ‘ Insert your comments here
          ‘——————————————————————————-

          Sub Main(Client, GWEvent)

          Dim objAddressBooks
          Dim objAddessBook
          Dim objAddressBookEntry
          Dim objSubject
          Dim objMessage
          Dim objMsg
          Dim objAttach
          Dim objAttachs
          Dim iAttachCounter
          Dim iMsgID
          Dim iFilter

          Set objMsg = GroupWise.ComposingItem
          objSubject = objMsg.Subject
          objMessage = objMsg.BodyText
          ‘ iFilter = GroupWise.FilterReset()
          ‘ msgBox(iFilter)

          ‘ Get the composing message ID through TOKEN
          iMsgID = GroupWise.ItemMessageIDFromView
          ‘ Make sure we have a composing message selected
          iAttachCounter = GroupWise.ItemAttachmentGetCount(iMsgID)
          if (iAttachCounter > 0) then
          for x = 0 to (iAttachCounter -1)
          objAttach = objAttach & GroupWise.ItemAttachmentGetName(iMsgID, x) & “;”
          next
          objAttachs = Split(objAttach, “;”)
          end if

          ‘ Get the AddressBooks object
          Set objAddressBooks = GroupWise.Account.AddressBooks
          ‘ Locate the address book called ‘Address Book’

          Set objAddressBook = objAddressBooks.Item(“Contacts for Newsletter”)

          ‘ Display the email address of each entry in the book

          For Each objAddressBookEntry In objAddressBook.AddressBookEntries
          if objAddressBookEntry.emailaddress <> “” Then
          ‘ Create new mail message
          Call GroupWise.NewMail
          ‘ Enter the recipient
          Call GroupWise.FocusSet(fcsTo, “”)
          Call GroupWise.TypeText(objAddressBookEntry.emailaddress)

          ‘ Enter the subject
          Call GroupWise.FocusSet(fcsSubject, “”)
          Call GroupWise.TypeText(objSubject)
          ‘ Enter the message body, first insert the greeting from contact comment field
          ‘ after that enter the text as type in the previous window
          Call GroupWise.FocusSet(fcsMessage, “”)

          Call GroupWise.TypeText(objMessage)
          ‘ Add attachment if any
          if (iAttachCounter > 0) then
          ‘ Loop through attachments to get the names
          for x = 0 to (iAttachCounter -1)
          call GroupWise.ItemAttachmentAdd(“X00”, itcAttachClassFile, objAttachs(x), “”)
          next
          end if

          ‘ Send the message
          Call GroupWise.ItemSend(False)
          Utilities.doevents
          end if
          next

          Set objAddressBook = Nothing
          Set objAddressBooks = Nothing
          Set objMsg = Nothing

          #7855
          Support 3
          Participant

            We are not sure why you want to use the split method to extract the substrings instead of the stringlist approach we recommended earlier. You will need to test your code to make sure it is robust taking into consideration that you may need to process extreme data. For example, if a message has a file name which contains semicolon (e.g. “test;file.gif”) then your split function will return incorrect result.

            We always try to respond a question where possible. It’s often worthwhile posting these type of questions to the appropriate VBScript Forums on the web.

            Regards,
            Advansys Support

          Viewing 3 replies - 1 through 3 (of 3 total)
          • You must be logged in to reply to this topic.