6 Replies Latest reply on Feb 5, 2014 9:52 AM by MrMunchkin

    Script to email copy of database using filemaker go

    MrMunchkin

      Title

      Script to email copy of database using filemaker go

      Post

           Hi,

           I would like to create a script which will allow me to make a copy of a filemaker go database (using iPad with filemaker go 13) and attach it to an email with a pre determined email address and subject filled in. The idea is that the user will only have to press one button within filemaker go and this will do all the work to send the email (the user will only need to press send in the mail app, everything else would already be filled in and attached).

           I have managed to almost create this using exporting as a .csv file but i cannot get it to work with the full database file or copy of the database file.

           The closest i can get is creating the email with the attachment but I need to fill the to: and subject: data in myself. I would like a process where we don't need to do this.

           Is there anybody who can help? I would really appreciate it.

        • 1. Re: Script to email copy of database using filemaker go
          TSGal

               MrMunchkin:

               Thank you for your post.

               In the "Send Mail" script step, you do have the ability to enter the "To:", "Subject", and "Message" fields.  Here is the script:

               Save a Copy as [ "TEST.fmp12" ; copy ]
               Set Variable [ $FilePath ; Value: "file:" & Get ( DocumentsPath ) & "TEST.fmp12" ]
               Send Mail [ Send via E-mail Client ; No dialog ; To: <email address> ; Subject: <your subject>; "$FilePath" ]

               -----

               The first line saves a copy of the current file and names it TEST.fmp12.  The second line sets a variable to the path of where the file is stored.  The third line is the Send Mail script step, where you set the values for the different fields (only To: and Subject: are listed here for brevity) and attach the file ($FilePath).

               Let me know if you need additional clarification.

               TSGal
               FileMaker, Inc.

          • 2. Re: Script to email copy of database using filemaker go
            MrMunchkin

                 Hi TSGal,

                 Thanks for your email. I am working through your solution and am having trouble knowing what to put in the set variable fields.

                 When I click specify it displays a box

                 Name:

                 Value:

                 Repetition: 1

                  

                 next to value and repetition it says specify which when i click it opens up a calculation box

                  

                 could you outline what text/data i need to input into each field

                  

                 Thanks in advance

            • 3. Re: Script to email copy of database using filemaker go
              TSGal

                   MrMunchkin:

                   For Name, enter:  $FilePath

                   For Value, enter: "file:" & Get ( DocumentsPath ) & "TEST.fmp12"

                   Leave the Repetition value at 1.

                   -----

                   In the Send Mail script step, for the File attachment, enter:  $FilePath

                   TSGal
                   FileMaker, Inc.

              • 4. Re: Script to email copy of database using filemaker go
                MrMunchkin

                     Hi TSGal,

                     Thanks for your explanation. It worked great. Very happy now.

                     One thing I have noticed is that by doing it this way, it saves a copy on the device and when I run the script again it says that it "could not be created. Use a different name or make more room on this device". I guess this is because the copy with the same filename has already been created on the device and won't allow another file with the same name at the same time.

                     Is there any way to run this script and then implement a script which will delete the copy file on the device? This would make room for the script to be run again and be able to save to the device.

                • 5. Re: Script to email copy of database using filemaker go
                  TSGal

                       MrMunchkin:

                       FileMaker Go cannot delete a file from a script.  This can only be done at the home screen.

                       Perhaps when you save the file, append something unique to the filename.  Assuming you won't be sending the file more than once per day, use the current date.  Since you can't have slashes in the file name, you may want to either replace the slashes with underscores, or append the date in the format YYYYMMDD.  For example, modify the script above to:

                       Set Variable [ $FileCopy ; "TEST" & Let ( cd = Get ( CurrentDate ) ; Year ( cd ) & Right ( "0" & Month ( cd ) ; 2 ) & Right ( "0" & Day ( cd ) ; 2 )) & ".fmp12" ]
                       Save a Copy as [ $FileCopy ; copy ]
                       Set Variable [ $FilePath ; Value: "file:" & Get ( DocumentsPath ) & $FileCopy ]
                       Send Mail [ Send via E-mail Client ; No dialog ; To: <email address> ; Subject: <your subject>; "$FilePath" ]

                       -----

                       The first line places the current date in YYYYMMDD format after "TEST" and stores it in the variable $FileCopy.

                       The next line saves the modified filename to the FileMaker Go work area.

                       If you want a space between "TEST" and YYYMMDD, then change "TEST" to "TEST ".  (Notice the space after the last "T").

                       Let me know if you need additional clarification.

                       TSGal
                       FileMaker, Inc.

                  • 6. Re: Script to email copy of database using filemaker go
                    MrMunchkin

                         Hi TSGal,

                         Thanks again for your quick reply and answer to my problem. 

                         For some reason, everything seems to be working OK no. I am not sure why the error message came up before, but I have tested it again and it seems to be working. I will look at it again this evening and will go through your suggestion such as adding a unique identifier to the filename.

                         Thanks again.

                         You are awesome :)