Support 3

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.


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

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)
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), "")

    end if

   ' Send the message
   Call GroupWise.ItemSend(False)
  end if

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

set oAttachmentsList = nothing

End Sub

Advansys Support