6 Replies Latest reply on Feb 26, 2014 8:05 AM by mgaslowitz

    Email Multiple Attachments with 360Works Plugin


      I am trying to email multiple attachments using 360Works Plugin, but I seem to only send the last attachment in the Loop. I guess i don't quite understand how to invoke the EmailAttachFile (data) function correctly. The two main commands i use to create an email message and add attachments are:

      Set Variable[$Result; Value:EmailConnectSMTP("smtp.comcast.net) and EmailCreate (From; To; EmailSubject) and EmailAttachFile($TempFilePath)]


      Then later:


      Set Variable[$AddAttachment; Value:$AddAttachment and EmailAttachFile($TempFilePath)]


      I also Tried:


      Set Variable[$Result; Value:$Result and EmailAttachFile($TempFilePath)] and also Set Variable[$Result; EmailAttachFile($TempFilePath)]. None seem to resolve this issue. Only the last attachment is sent.


      One thing I don't understand is why i have to set a variable to invoke the EmailAttachFile function.


      For more info on 360Works plugin: http://static.360works.com/plugins/EMAILPLUG/documentation.html#EmailAttachFile


      The snipet of code I am using is attached.


      Any help to get me unstuck would be greatly appreciated.







      (Note: i didn't know initially that i could get a file directly out of a container field and into an email. That's why i first exported it to a tempfilepath. When i rewite this code, i will change the approach).

        • 1. Re: Email Multiple Attachments with 360Works Plugin

          I'm not entirely sure, but when you invoke the variable to set the attachment, you do not need to include the previous iteration of the $AddAttachment variable.


          So I think you need to change:

          $AddAttachment and EmailAttachFile( $TempFilePath )


          to just

          EmailAttachFile( $TempFilePath )


          Also, you used "and" instead of "&", which I believe is also problematic ("and" is used for conditional/boolean statements, IE "1=1 and 2=2", when you are concatenating two things into a single string, you need to use "&" ).


          Usually plugin functions that "cache" data for use elsewhere, or perform actions outside of the calculation engine, will require a method to activate the function. Thus calling a variable will perform said action in this case. The plug-in supports multiple attachments by allowing you to call the EmailAttachFile() function numerous times before using the EmailSend() function. So you will "cache" all of your attachments until you send the email.


          There is no need to create a list of previous attachments as your highlighted line suggests.

          1 of 1 people found this helpful
          • 2. Re: Email Multiple Attachments with 360Works Plugin



            One of the other things you should do is to add some error checking to your script. Most of our plugin functions will return a 1 if the function performed properly, and the word ERROR if it did not. Attached is a sample file that you can you use for testing. I can confirm that it works properly with 360Works' SMTP server.


            Please let me know if you continue to have trouble



            1 of 1 people found this helpful
            • 3. Re: Email Multiple Attachments with 360Works Plugin

              Thank you Mike. This is very helpful, between your answer and Michael G.'s answer below, a lot is clarified. One of the key miss on my part was the lack of understanding what the variable returned by the plugin was conveying information about success or error in carrying the command.


              I followed Mike G's example, and could understand most of it, except ADD ATTACHMENT section of the code. I get that the code reads the attachments in a fixed length Value List (5 container items). In my situation, a Project can have many Attachments (Project table - one to Many Relation to - Attachment table), some attachments are flagged to be included in the email. My question is how do i create a Value List with variable length (I think repetition is the terminology in FM)?

              I am not clear on how to create the equivalent of an array of variables. I think Value List would be the way to go.


              Again, thank you Mike for your help, now and in previous posts.





              Screen Shot 2014-02-25 at 4.01.08 PM.png

              • 4. Re: Email Multiple Attachments with 360Works Plugin



                Your answer and suggestions for error checking was very helpful. Please see my follow up question above in my response to Mike Bergie. My question is more a generic question about how to create a value list of variable dimension.


                Thank you again for your help.



                • 5. Re: Email Multiple Attachments with 360Works Plugin

                  Value list is return delimited text, so not need in your case (use files in container, not the filenames in text field).

                  Loop through related record like as

                  If[GetNthRecord(Attachment::flag;$n)="to be included"]


                  • 6. Re: Email Multiple Attachments with 360Works Plugin

                    Since you're dealing with related records, I would use FileMaker's Count function to figure out how many records you are going to loop through and use that as the exit condition in your loop. Just be sure to use a field that you know has a value (like a primary key). Then use the code that user19752 used. This why you don't even have to have a portal on the layout for it to work.



                    Set Variable [ $itemCount ; Count ( Attachment::id ) ]




                        Exit Loop If [ Let ( $i = $i + 1 ; If ( $i > $itemCount ; Let ( $i = Null ; True ) ) ) ]


                         If [ GetNthRecord(Attachment::flag;$n)="to be included" ]


                              SetVariable[ $attach ; EmailAttachFile(GetNthRecord(Attachment::container;$n))]


                         End If


                    End Loop