9 Replies Latest reply on Sep 12, 2011 4:08 PM by philmodjunk

    Problem creating PDF of record/layout, attach to email, send email, loop through remaining

    straka_sh

      Title

      Problem creating PDF of record/layout, attach to email, send email, loop through remaining

      Post

      I have a database of boy scout groups... the products and quantities each group has sold as well as total $ amounts, etc... I've created a layout that puts it all together, and the boy scout leaders would like a PDF attached to an email sent to each group/unit with their information on it... I'm very close to getting this to work, but the emails I'm creating only have the first record created as the PDF and attached to every email instead of each email having its own PDF of information.

      My script:

      Sort records [by unit]

      Enter Preview Mode

      Goto Record/request/page [first]

      Loop

             Save Record as PDF [Restore; No dialog; "Email_Report_SNS_Pick_Ticket.pdf"; current record]

            Send Mail [Send via Email Client; To: ***, Subject: ***, Message: ***; Attach file: Email_Report_SNS_Pick_Ticket.pdf"

            Insert Current Date [Select: Email_PDF_Flag] (to show that record has been sent)

             Goto Record/request/page [Next; Exit after last]

      End loop

      Enter Browse Mode

       

       

       

      Pick_Ticket_Email_9_12_11.JPG

        • 1. Re: Problem creating PDF of record/layout, attach to email, send email, loop through remaining
          philmodjunk

          Yeah that won't work, as you've discovered.

          Your save as PDF step has two key optiosn: Current Record or Records being browsed. Since you don't want to send just the current record here, that's why the PDF has only one record in it, you need to perform a find or do a go to related records to pull up the found set of records you want for your report, then do the Save as PDF with the Records being browsed option.

          Seems to me that you also need a different table where you have one record for each group or unit and their email address so that you can loop through that table instead of the one shown here--finding "their information" on the above layout and saving it as a PDF.

          • 2. Re: Problem creating PDF of record/layout, attach to email, send email, loop through remaining
            straka_sh

            Phil,

            Thanks for your response.

            Few questions/clarifications:

            1. But if the script is looping through the records, why wouldn't each next record become the "current record" and get saved then emailed separately... then move on to the next?

            2. I do have these fields in this table: Council Name, Order Type, District Name, Unit Type, Unit Number, Leader's Name, Leader's Email, Pick Up Location, Total Gross Amount Due, Products 1-15, Qtys 1-15, etc... which create 1 record for each unit of Boy Scouts.

            3. I had no problem getting this to work earlier by creating the PDF with saving "All records being browsed" option... however, I cannot send all 70 pages of records (1 for each unit) to each Boy Scout Unit... they'd see each other's info and how much every other group sold, etc...

            4.  How can I use that information to loop through all 70+ units of Boy Scouts, and create the PDFs separately (1 for each record) and get them attached to the emails?  How would I use the "find" mode in the script to do so or another way?

            Thanks again!

             

             

            • 3. Re: Problem creating PDF of record/layout, attach to email, send email, loop through remaining
              philmodjunk

              1. But if the script is looping through the records, why wouldn't each next record become the "current record" and get saved then emailed separately... then move on to the next?

              I assumed from your screen shot that each group's report entailed multiple rows, (Therefore multiple records) of data and that each should be receiving a different set of those records. I read your description of "first record only" as indicating that only the first row of data was being sent instead of all the rows. If this is not the case, then please disregard this suggestion.

              I'm wondering if the PDF saved is really the email that is being attached in the send mail step. I know that you have the same file name specified, but I'm not sure that they both refer to the same location.

              I generally use a variable to control the file names and file paths specified for both the save as PDF and Send Mail steps: Found Sets to PDF with unique file names

              • 4. Re: Problem creating PDF of record/layout, attach to email, send email, loop through remaining
                straka_sh

                 Phil,

                Thanks again for your suggestions...

                This view/screenshot shows just 1 record... each record has: Boy Scout Unit, Unit number, Unit leader name and email, $ Due, all the product descriptions, quantities, etc...

                It's hard for me to believe this seems so hard for me to figure out... seems like a fairly straitforward action to perform... make PDF of separate records and attach them to separate emails (sent to a unit leader who is in a field in the record)...

                I'll try the variable script idea...

                Does it change anything/make it easier knowing each screenshot/layout is only 1 record?

                Thanks again for your expertise

                • 5. Re: Problem creating PDF of record/layout, attach to email, send email, loop through remaining
                  straka_sh

                   Phil,

                  I've tried using variables... still no luck... seems to not getting past saving only first record as pdf and always attaches (the first record) it to the email (even when body of the emails has each new record's field info in them)...

                  The file is very simple... because I've only imported the records/data I need to perform this email... Is there any way to let you take a quick look at the file itself?

                  Thanks again for your help...

                   

                  Shannon

                  • 6. Re: Problem creating PDF of record/layout, attach to email, send email, loop through remaining
                    philmodjunk

                    Can you post the current version of your script here? A screen shot or a copy/paste of the script as text would be best so we can see any of those picky little details that might mess up the script's function here.

                    I still have a sneaking suspiscion that the PDF file being attached is not the same copy of the file being saved--so a search of your computer for all instances of this filename might be enlightening.

                    To post a script to the forum:

                    1. You can upload a screen shot of your script by clicking the edit link to your original message and uploading it there
                    2. You can upload a screen shot to a file share site and post the download link to a new response you post here.
                    3. You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF.
                    4. If You have FileMaker advanced, you can generate a database design report and copy the script as text from there.
                    5. If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional look to your script. (Use the HTML option and paste the text into the HTML editor.)
                    • 7. Re: Problem creating PDF of record/layout, attach to email, send email, loop through remaining
                      straka_sh

                       Phil,

                      It finally works... but only after I stopped trying to be really specific with the file path... it kept telling me I couldn't save with that file name, or the disk was full, etc... so I made the variable $filename which utilizes a filename field in each record and adds ".pdf" and made everything very simple... now it will save each individual pdf to my desktop and attach it to the email...

                      • 8. Re: Problem creating PDF of record/layout, attach to email, send email, loop through remaining
                        straka_sh

                         If you'd like to see the latest script that actually does the work as intended, I can give you a new screen shot of the script...

                        • 9. Re: Problem creating PDF of record/layout, attach to email, send email, loop through remaining
                          philmodjunk

                          OK, I think that additional info explains it. Do you specify that the PDF be opened when it is saved? If so, the next loop around can't save the next PDF to the same file name as the file is open and this keeps filemaker from overwriting it. By using unique file names, you avoid that issue. If I'm right, you can clear that option for opening the PDF and then use the same file name for each and still get this to work without an error message.

                          (All that error message really means is "I can't save the file to the disk for some reason.." Wish it said something like that instead of the much more confusing message that attempts to diagnose why it couldn't save the file.)