11 Replies Latest reply on Oct 20, 2008 10:59 PM by davidhead

    Naming a PDF

    Fratco

      Title

      Naming a PDF

      Post

      I need to write a script that saves a record as a PDFn pulls the name from a field (IDDPS) and saves it on our server. I am having trouble with the Variable feature to name the PDF.

        • 1. Re: Naming a PDF
          AndreasT
             Can you provide a few more details on the issue you are having?

          What specifically do you need assistance with in the script?
          • 2. Re: Naming a PDF
            Fratco
              

            I know how to save the record as a PDF. I want to give the PDF a name based on the field "Company Code"as part of the script and then save it in a specified file path (I know how to do that, too). It is the attaching the field as the PDF name that is giving me the trouble.

             

            Thank you for your help

            • 3. Re: Naming a PDF
              davidhead
                

              What you need to do here is to store the complete file path (including the file name) in a variable first. Then you use that variable as the output file path for the PDF. The script might look something like this:

               

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

              Save Records as PDF [Restore; No dialog; "$file"; Current record] 

              • 4. Re: Naming a PDF
                AndreasT
                   Ok, thanks for the clarification.

                Basically the variable needs to contain the full path including the file name and extension.

                Lets say you want to save the file to the Desktop, the variable declaration might look like this.

                $myfile=
                Get(DesktopPath) & YourTable::Company Code & ".pdf"

                In the Save Records as PDF output settings you enter file:$myfile

                You should employ some validation of the Company Code to ensure that it contains only valid characters for file names.
                Error checking is a good idea to catch any file system errors.
                • 5. Re: Naming a PDF
                  Fratco
                    

                  Andreas,

                   

                  Thanks for the help. I'm getting there, but what do I substitute for "$myfile"?

                  • 6. Re: Naming a PDF
                    AndreasT
                       $myfile is the name of the variable used in the Set Variable Script step.
                    • 7. Re: Naming a PDF
                      Fratco
                        

                      Set Variable [$IDDPS; Value:Sales::IDDPS & Get (DesktopPath) & Sales::IDDPS & ".pdf"]

                      Save Records as PDF [Restore; No dialog; "$IDDPS"; Current Record]

                       

                      In this script  "IDDPS" is the field name that I want to name the file; Sales::IDDPS is the table and field.  I want the file to save on my "P" drive in a folder named "Garnishments".

                       

                      I get an error message saying that I can't save on this disk.

                       

                      I'm sorry to be so stupid on this but it is my first time using variables and I am not doing very well so far.

                       

                      Thanks for your help

                       

                      Fratco

                       

                      • 8. Re: Naming a PDF
                        AndreasT
                          

                        Fratco,

                         

                        You have it almost right, you need to rearrange the sequence of the parameters in your variable, something like this.

                         

                        Set Variable [$IDDPS; Get (DesktopPath) & Sales::IDDPS & ".pdf"]

                         

                        Try that first and see if you get it to save to the desktop, then you can create the path you need and substitute that in for Get (DesktopPath).

                        • 9. Re: Naming a PDF
                          Fratco
                            

                          Andreas,

                           

                          Thanks for responding; however, I am getting a message that says "SRR2.pdf could not be created on this disk. Use a different name, unlock it or use a different disk."

                          (SRR2 is the record in the field, so that is working)

                          When I try and substitute a filepath like "filewin:/P:/Garnishments in place of Get (DesktopPath) it is looking for a field. 

                           

                          What is the proper way to substitute (Get (DesktopPath) with the file path on my "P" drive.

                           

                          Fratco

                          • 10. Re: Naming a PDF
                            AndreasT
                              

                            Fratco,

                             

                            Do you have Filemaker Advanced? If you do you can check the value of your variable as it is assigned using the Data Viewer and the Script debugger to step through one step at the time.

                            That way you can spot any mistakes you may have in the file path.

                             

                            Also, make sure you are beginning and ending your custom filepath with quotes so that Filemaker understands that it is a text string and not a field reference.

                             

                            Your path looks good as long as you have write privileges to that folder.

                             

                            If you include the prefix filewin: directly in your variable, make sure that you only enter the variable name in the PDF output settings without any file: prefix.

                            • 11. Re: Naming a PDF
                              davidhead
                                


                              Fratco wrote:

                              ... I am getting a message that says "SRR2.pdf could not be created on this disk. Use a different name, unlock it or use a different disk."


                              Fratco
                              Did you ever try my code?

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

                                   Save Records as PDF [Restore; No dialog; "$file"; Current record] 
                              I have found in the past that prefixing with "file:" avoids the sort of error you are seeing and there is no need for Mac?PC versions.