3 Replies Latest reply on Apr 27, 2014 8:08 AM by philmodjunk

    Writing script to e-mail a days worth of records

    JordanBommelje

      Title

      Writing script to e-mail a days worth of records

      Post

           At the end of the night, I'd like for someone to click on a button that sends an end of day recap. All this does is selects the records for that day and sends it in a human readable form. PHP and MySQL is much more different!

        • 1. Re: Writing script to e-mail a days worth of records
          philmodjunk

               You'll need to decide on a file format. My guess is that you will want to email a PDF, but this is not the only option. If the recipient has access to the database, for example, you might send a snapshot link and you can send an excel file if the recipient likes to use Excel.

               There are several sub tasks to what you want:

                 
          1.           A script that automatically runs at the end of the day (or you can click a button to do this at the end of each business day...)
          2.      
          3.           Pulling up a found set of today's records via a script
          4.      
          5.           Saving a PDF (or other file format) of the found set of records.
          6.      
          7.           Sending an email to the designated recipient with the PDF (or other file) attached to the PDF (or if your needs are modest, maybe just listed as text in the body of the email.)


               1. scheduling this can be a bit complicated as you can't use a server schedule to do this since Save As PDF is not server compatible. You can, however, set up a script that runs when a specific session of the database file is closed or a "robot" FileMaker file can be set up to connect to the database and perform the script that can then be scheduled via an OS based scheduling utility such as Windows Scheduled Tasks.

               2. The scripted find can be pretty simple if you have a date field that identifies all of "today's records". There are many scripted find examples in the following script, one uses Get ( CurrentDate ) to find all records with today's date in a date field: Scripted Find Examples

               3. see this thread: Found Sets to PDF with unique file names

               4. Step 3. uses a $path variable to save the PDF to a specified location and file name--which can be the temporary folder. You can then add a Send Mail script step to send the email, click the attachment check box and type in the name of this path variable to attach the PDF just generated to the email. (Note it can take a few seconds to create the PDF, you may need to add a pause/resume script step that pauses the script for a few seconds to make sure that the PDF is created before the send mail step executes and tries to send it.

               For more on $Path variables and the script steps that can use them, see: Exploring the use of a $Path Variable in Scripts

          • 2. Re: Writing script to e-mail a days worth of records
            JordanBommelje

                 Sorry it took me a while to actually go through this. I've created the script and it finds all of today's records, now I need to add those to an e-mail. You've got notes for creating a PDF, but my needs are actually pretty modest. I just need to send the text in an e-mail. The only thing I'd like to add is that I have a container field that a PDF will be added to that I would like to add as an attachment to the e-mail. 

            • 3. Re: Writing script to e-mail a days worth of records
              philmodjunk

                   I just need to send the text in an e-mail. The only thing I'd like to add is that I have a container field that a PDF will be added to that I would like to add as an attachment to the e-mail.

                   I can't follow what you mean by that. Can you provide an example of what you need? I've provided info on how to save a PDF but what role does the container field play in this? And how is it that you want to send text in an email but also have a PDF?