1 of 1 people found this helpful
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 )
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.
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
Email Sample.fmp12.zip 12.8 K
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.
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.
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"]
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))]