1 2 Previous Next 15 Replies Latest reply on May 28, 2010 12:29 PM by hehazelhorst

    Generating file names when creating PDF's



      Generating file names when creating PDF's


      Is there a way to automatically generate file names via a calculation when using the Save Records as PDF script?  (i.e. <job#>"-specs".pdf)



      We are using Filemaker Pro 10 Advanced and Filemaker Server 10 Advanced. Filemaker Server Advanced is running on a Windows PC server. We have about 25 Filemaker client users (both Mac & PC). We also have non-Filemaker client users for employees company wide to access a couple of layouts via Custom Web Publishing. Our company has been using this Filemaker database since 1998. I personally have been using Filemaker since the late 1980’s when it was called Claris Works. We just recently upgraded from Filemaker 5 to Filemaker 10 and are in the process of a major overhaul of the entire database. Records in the main table represent individual marketing jobs (usually print jobs - i.e. brochure, forms book, mailer, etc.). Then, we have about 18 related tables for tracking various aspects of a job through the production schedule, from job initiation to completion. It tracks milestone due dates, design specs, licensing information, inventory, distribution, costs, etc.


        • 1. Re: Generating file names when creating PDF's

          In my script I use the following:

          Set Variable [ $fileName; Value:"file:" & Get(DesktopPath) & "GenerateForms" & ".pdf" ]

          • 2. Re: Generating file names when creating PDF's

            Forgot to add that after I set the variable the script line for Save to PDF:


            Save Records as PDF [ File Name: “$fileName”; Current record ]

            • 3. Re: Generating file names when creating PDF's

              I'm not sure exactly what you mean by these instructions as I have been living in the dark ages of FM5 for so long.  I love all the new features in FM10 but am still on a learning curve on the new features.


              I am creating a Send Mail script which attaches a pdf file created using a Save Records as PDF sub-script.  I get how to do all of this except how to create and use a dynamic file name.  I would like to name the file via a calculation in the Save Record as PDF script.  The file will be named using data from the "Job_Number" field followed by "specs.pdf" and should be saved in a "SpecSheets" directory on the users desktop (i.e. the spec sheet pdf for the Job #123456 would be  "123456specs.pdf"). 


              Then, I also do not know how to have the Send Mail script retrieve and attach the 123456specs.pdf from the SpecSheets directory on the desktop when the script is executed via a Submit Specs button on the Spec Sheet layout for Job #123456.


              Can calculations be used in the file paths in both types of scripts.  Please be specific with instructions using my example.  Like I said, I've been living in the dark ages and never used these scripts before. 

              • 4. Re: Generating file names when creating PDF's

                To create your PDF Save script with the Job Number ID field as part of the filename your script should look something like the following:


                Set Variable [$fileName: Value, "file:" & Get(DesktopPath) & JobTable::Job_Number & "specs.pdf"]

                Go to Layout ["Job Report" (JobsTable)]

                Print Setup [Restore; No Dialog]

                Enter Preview Mode []

                Save Records as PDF [Restore; No Dialog; "$fileName"; Current Record]

                Enter Browse Mode[]

                Go to Layout ["Job Enty Form" (JobsTable)]


                I have not been successful at getting the PDF to save inside a folder on the desktop as of yet.  If no one responds to that specifically, perhaps you can create another post with a subject line asking just that.  As well as, the Send Mail - retrieving and attaching a file.


                I would presume that calculations can be included in the filepath commands, using the variable step.  Not sure exactly how to do that yet either... I'm still a novice.  





                • 5. Re: Generating file names when creating PDF's

                  When specifiying the file path the back slash \ has to be replaced with a forward slash /

                  if you look at the specify output file part of the script step it shows examples of how the file path shoud look. remember to include the header part ie filewin:// in your calculated path.

                  In senriz's example he generates a local variable to hold the file path called $fileName (the $ is critical as it identifies it as a local variable in the script) he then concatenates (links together into one long string) using the & command

                  "file:"  relative path identifier

                  Get(DesktopPath) returns the directory path for the desktop folder

                  JobTable::Job_Number  your field which holds the jobnumber

                  "specs.pdf" the final part of the filename you want.


                  if the job number was 12345

                  the variable would hold something like file:/C:/Documents and Settings/manning/Desktop/12345specs.pdf

                  Get(DesktopPath) actually returns /C:/Documents and Settings/manning/Desktop/ so make sure you dont add to many /

                  I save a report of new quotes to send to our sales guys using the following path filewin://Ukex-as-1/filemaker/Reports/New quotes.pdf it is run from the remote database and saves on the server where filemaker server 10 is installed.


                  I hope this helps


                  • 6. Re: Generating file names when creating PDF's

                    This works perfectly!


                    Thank you Senriz & Ian.

                    • 7. Re: Generating file names when creating PDF's

                      I run into an error when trying to write records to a PDF.


                      I use these scriptsteps:

                      Set Variable [$fileName ; Value: "file:"  & Get ( DesktopPath ) & "MyNewReport" & ".pdf"]

                      Save Records as PDF [$fileName" ; Records being browsed]


                      This brings up the usual dialog box where I specify some PDF options, which I click OK.


                      Then the error message displays:

                      "MyNewReport.pdf" could not be created on this disk. Use a different name, make more room on the disk, unlock it or use a different disk.


                      I am using FileMaker Pro 10 on MacOSX 10.6 and have admin rights on the disk!

                      What am I doing wrong here? FMP apparently evaluates the proper filename...



                      • 8. Re: Generating file names when creating PDF's

                        Some extra information:


                        I can save records to PDF manually, the file is created with no problems at all!


                        Only when trying to use a script the error msg appears!


                        And with FileMaker 9: same error. Also tried FMP 8.5 Advanced on Windows XP: same error.



                        • 9. Re: Generating file names when creating PDF's

                          My first step would be to use the script debugging available in FMPro advanced or to add a script step which pastes the complete file name variable into a global field so that you can check that it is what you think it is.

                          Try replacing the Get(desktoppath) with a fixed path like /c:/ start with the simplest file path, no calculations or anything then when that works gradually build the path in the way you want. Look out for illegal characters, very long paths, virtual paths, mapped drives etc they can all cause problems.



                          • 10. Re: Generating file names when creating PDF's



                            The syntax you post works for me on my XP system....


                            You might try adding the script step Show Custom Dialog [$fileName] just to check to see if any obvious errors are being included when this path is calculated.

                            • 11. Re: Generating file names when creating PDF's

                              I had the same problem and performed all the steps posted by Ian Manning, unfortuantely I can't recall how I resolved that issue at this moment, but looking at your complete script might jog my memory.  Can you post your complete script?

                              • 12. Re: Generating file names when creating PDF's

                                i've encountered this problem before as well and it had to do with the file name not being unique.

                                When you ran this script, was there already a file on your desktop titled "MyNewReport.pdf"?

                                • 13. Re: Generating file names when creating PDF's

                                  My tests with an XP system indicate that if the PDF file name already exists, it will be overwritten by the new PDF file.


                                  My script step:

                                  Set Variable [$Path ; Value:  "file:" & Get ( DesktopPath )  & Substitute ( Table::Field &  " " & Get ( CurrentDate) ; "/" ; "-" ) & ".PDF"


                                  As suggested earlier, you have to make sure that your computed file name does not include any characters that aren't permitted as part of a filename or you'll get the generic error message described in this thread.

                                  • 14. Re: Generating file names when creating PDF's

                                    Do you have the PDF open? If you have it open you will get this error wehny ou run the script to generate it.

                                    1 2 Previous Next