WF7A Posted December 22, 2022 Share Posted December 22, 2022 (edited) I've coded a script (attached) that successfully sends a scripted e-mail (from FM Server v19.x) that includes a .pdf as an attachment, but I'm just wondering if there's been any progress in being able to send multiple .pdfs in the same/one e-mail without resorting to having to use a plug-in; the threads I've been reading here and elsewhere stem from 2016, so if there's been any progress since then to being able to send such e-mails without using plug-ins I'd appreciate being pointed in the right direction. Happy holidays, Rich Email Script_Redacted.pdf Edited December 22, 2022 by WF7A Link to comment Share on other sites More sharing options...
Ocean West Posted December 22, 2022 Share Posted December 22, 2022 You need to get a list of files paths on documents path or temporary path and then assign them to variables add that to the send mail script. Link to comment Share on other sites More sharing options...
WF7A Posted December 22, 2022 Author Share Posted December 22, 2022 (edited) Let's say that a relationship exists and the .pdf field lives on the child table. Wouldn't I have to loop through all the related child records to create each its own variable (using Get (TemporaryPath) ) for each record, e.g, $_TempPath1, $TempPath2, $TempPath3? If so, is there an elegant way to serial increment the $TempPath variable name (for Get ( TemporaryPath ) & GetContainerAttribute ( ATTACHMENT::PDF__lxr ; "filename" ))? Edited December 22, 2022 by WF7A Link to comment Share on other sites More sharing options...
Ocean West Posted December 22, 2022 Share Posted December 22, 2022 # # Set Variable [ $i ; Value: 1 ] Go to Object [ Object Name: "portal" ] Go to Portal Row [ Select: On ; First ] Loop Set Variable [ $x ; Value: child::path ] Set Variable [ $y ; Value: "Let ( $temp" & $i & " = \"" & $x & "\" ; \"\" )" ] Set Variable [ $z ; Value: Evaluate ( $y ) ] Go to Portal Row [ Select: On ; Next ; Exit after last: Off ] Set Variable [ $i ; Value: $i + 1 ] Exit Loop If [ $i > 5 ] End Loop Send Mail [ Send via E-mail Client ; With dialog: On ; 5 Attachments ] path.fmp12 Link to comment Share on other sites More sharing options...
comment Posted December 23, 2022 Share Posted December 23, 2022 (edited) 5 hours ago, WF7A said: a relationship exists and the .pdf field lives on the child table I was curious to see what would happen if a single variable contained multiple filepaths. In my test, I am getting a draft mail containing multiple PDF attachments, one from each related child record. This is my script: If [ not IsEmpty ( Child::ParentID ) ] Go to Related Record [ From table: “Child”; Using layout: “Child” (Child) ] [ Show only related records ] Go to Record/Request/Page [ First ] Loop Set Variable [ $filePath; Value:Get ( TemporaryPath ) & Child::Name & ".pdf" ] Set Variable [ $allPaths; Value:List ( $allPaths; $filePath ) ] Export Field Contents [ Child::PDF; “$filePath”; Create folders:No ] Go to Record/Request/Page [ Next; Exit after last ] End Loop Go to Layout [ original layout ] Send Mail [ Send via E-mail Client; To: Parent::Email; Subject: "Important Subject"; Message: "Here are your files"; Attachments: “$allPaths” ] End If This is undocumented, so YMMV. But if it works for you, then you won't need to name variables programmatically (which, as you have seen, is rather awkward) and - most importantly - you won't need to hard-code the variables into the Send Mail script and place an arbitrary limit on the number of attachments. 12 hours ago, WF7A said: I've coded a script (attached) Your script creates the PDF by using the Save Records as PDF script step. If that's where your PDFs are supposed to come from, then you also have the option to merge them into a single PDF, then attaching the resulting file. 12 hours ago, WF7A said: if there's been any progress I believe the direction of the progress is to move away from SMTP-based mail towards interacting with the mail provider's API using the Insert From URL script step. Currently this can be a rather challenging task; perhaps in the future Claris will include pre-made routines for the major providers. Edited December 23, 2022 by comment Link to comment Share on other sites More sharing options...
WF7A Posted December 23, 2022 Author Share Posted December 23, 2022 (edited) Thank you both VERY much. I got Comment's script to work, but couldn't get Ocean West's--I'm guessing it may have to do with the variable, $z, because it's defined but not used anywhere after that, so maybe a crucial instruction is missing? I agree with the SMTP-based e-mail vs. API. For a while, I've been using smtp-relay.gmail.com, but that stopped working so I created an account password per Claris's instructions and started using smtp.gmail.com, but you're right--an easy-to-use API would be grand ... especially for nim-nulls like me who have no concept of how to use them (as well as JSON--a double-whammy nowadays.) I took Productive Computing University's API course multiple times and I just don't get it; it's a nicely put-together primer, but I'm old and dense, so it's hard for this old geezer to grok. : P Edited December 23, 2022 by WF7A Link to comment Share on other sites More sharing options...
comment Posted December 26, 2022 Share Posted December 26, 2022 On 12/24/2022 at 12:40 AM, WF7A said: I'm guessing it may have to do with the variable, $z, because it's defined but not used anywhere after that The variable $z is used by the very act of its creation. You asked how to define a variable whose name is not known beforehand, and that's how it's accomplished - see: https://fmforums.com/topic/65364-dynamic-variable-name-is-it-possible https://fmforums.com/topic/86059-setting-variable-by-variable-name/?do=findComment&comment=395585&_rid=72594 But overall the idea you have outlined: On 12/23/2022 at 1:21 AM, WF7A said: to loop through all the related child records to create each its own variable (using Get (TemporaryPath) ) for each record, e.g, $_TempPath1, $TempPath2, $TempPath3 has a flaw I already mentioned earlier: these variables need to be hard-coded into the Send Mail script step. That means there will be a limit to the number of child records that can be included in this process. And if there is a known limit, then you could also simply create these variables explicitly, without resorting to the awkward technique above. 1 Link to comment Share on other sites More sharing options...
WF7A Posted March 16 Author Share Posted March 16 (edited) I'm bumping this thread because I've run into a snag. Sorry. The problem is when a user connects via WebDirect the above won't work, so my goal now is to enable a WebDirect user to be able to send an e-mail with a .pdf (stored in a Container field, externally-saved) as an attachment from a single record. From what I've read, a "trigger" script is necessary to fire a PSoS script that contains the instructions to do all this; I've attached what I've tried (and it fails.) It _seems_ to get hung up on the Export Field Contents instruction since when I try the Export As PDF instruction instead, the record layout is dutifully created as a .pdf and attached correctly...but I could be (am usually) wrong. TIA for your help! Untitled.pdf Edited March 16 by WF7A Re-upload of .pdf Link to comment Share on other sites More sharing options...
Ocean West Posted March 16 Share Posted March 16 Export Field Contents is not a server compatible script step you will need to install BaseElements plugin on server to export the PDF from a container you can use insert url to convert a generated PDF into a container. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now