7 Replies Latest reply on Jan 3, 2017 7:05 PM by tomswell

    Insert File script step problems


      Hi All.


      I have a strange issue with the script below. My client wants to drag a PDF into a container field (works great), automatically create a cover page, merge the two with the cover page on top and place the new PDF into a different container field. I export the original PDF to the temp directory, export a cover page PDF to the temp directory and then run a command line line app called pdftk to merge the two. All of the files are in the temp directory including the newly merged one. Everything works great until the Insert File script step. When Filemaker hits the Insert File step it will:

      1) Work

      2) Appear to work but nothing is inserted into the other container field

      3) Bring up the insert file dialog


      Obviously #1 is what I want all of the time. Does Filemaker have an issue with the temp directory perhaps? Is there something I'm missing? I've also tried using Insert PDF but that has been even less reliable.


      BTW, I'm using FM 13 and the clients DB is a hosted FM server 13.


      Set Error Capture [On]


      # Variables


      Set Variable [$X; Value:Inquiries::ClientRecords Temp]

      Set Variable [$TempRecord; Value:Get ( TemporaryPath ) & GetAsText ( Inquiries::ClientRecords Temp )]

      Set Variable [$TempSave; Value:Get ( TemporaryPath ) & "Temp Save.pdf"]

      Set Variable [$TempPath; Value:Get ( TemporaryPath )]

      Set Variable [$Litserv; Value:Inquiries::LitServ#]


      Export Field Contents [Inquiries::ClientRecords Temp; “$TempSave”]


      New Window [Style: Document]

      Go to Layout [“Records Cover Page” (Inquiries)]

      Enter Find Mode []

      Perform Find [Restore]

      Set Variable [$FaxCover; Value:Get ( TemporaryPath ) & "Fax Cover.pdf"]

      Save Records as PDF [No dialog; “$FaxCover”; Records being browsed]


      Set Variable [$Execute; Value:"cmd.exe /C pdftk \"" & $FaxCover & "\" \"" & $TempSave & "\" cat output \"" & $TempRecord & "\""]

      Set Variable [$Execute; Value:Substitute ( $Execute; "/"; "\\" )]

      Set Variable [$Execute; Value:Substitute ( $Execute; "\C:"; "C:" )]

      Set Variable [$Execute; Value:Substitute ( $Execute; "cmd.exe \C"; "cmd.exe /C" )]

      Set Variable [$NewPDF; Value:Right ( $Execute ; Length ( $Execute ) - Position ( $Execute ; " " ; Length ( $Execute ) ; - 1 ))]

      Set Variable [$NewPDF; Value:"filewin:" & $TempRecord]

      Send Event [“aevt”; “odoc”; $Execute]


      Go to Layout [“Inquiries Raw” (Inquiries)]

      Go to Field [Inquiries::ClientRecords]

      Insert File [Inquiries::ClientRecords; “$NewPDF”]

      Close Window [Current Window]


      Set Variable [$Exit_Script; Value:"Pause"]




        • 1. Re: Insert File script step problems

          Just a guess here. The external script you are calling to combine the files may not be completing quickly enough and your script is attempting to import something that is either non-existent or that is "in progress" (therefore possibly locked or in a format that FM cannot understand.


          Have you tried adding a small pause to the script to see if this is a timing issue? A timing issue would possibly manifest in the way you describe (sometimes working, other times failing)

          • 2. Re: Insert File script step problems

            I am guessing that the the problem lies with the content of the $NewPDF variable (Set Variable [$NewPDF; Value:"filewin:" & $TempRecord]). If you set the prefix to imagewin instead of filewin it should work. You need to use the image prefix for inserting, but the file prefix for export/save to PDF.


            Incidentally, I notice that you have consecutive SetVariable steps ($NewPDF x 2 lines). The second line will kill the value set by the first line. Is there an error there?

            • 3. Re: Insert File script step problems
              Stephen Huston

              If you export your PDF sections in the order you want them to appear — doing the page 1-x first — you can use the "Append" option in the Save to PDF script step to merge them from within FileMaker, and there won't be any OS-level process to wait for before importing the PDF.


              Note, I tend to include a pause of a second or so after the final append step to be sure the file has processed even from within FileMaker before trying to do something else with the file.

              • 4. Re: Insert File script step problems

                @deninger  I added a pause after the send event and it seems to help.


                @keywords I tried using fileimage but the insert file dialog always comes up. I'm guessing because the file has a PDF extension and FM is looking for an image type file. The first $NewPDF I was originally using so I could see various values in the data viewer. But thanks for noticing since I forgot to remove it.


                @Stephen Huston That's a good idea. Origianlly they wanted to drag several PDFs into temporary container fields and let Filemaker merge them so they wouldn't have to do it manually. Hence the DOS executable.


                The pause after send event seems to work but I will look into Stephen solution. I do occassionally get a "Container field can't be exported" message when the script is trying to export the original PDF. These can be quite large. The one I am testing with is 177 pages and they could be larger. The script is an on Modify trigger on the conatainer field. Maybe I should pause the script to make sure the PDF is completely loaded?


                Thanks All

                • 5. Re: Insert File script step problems

                  image: and imagewin: is used in 'Insert PDF' script step for interactive container.

                  Your case is not.

                  • 6. Re: Insert File script step problems

                    Re: "I tried using fileimage"  – That is not what I suggested.

                    • 7. Re: Insert File script step problems

                      i had insert problem using;


                      until the great phil found that;



                      insert "image;" &  $your_filepath &".pdf" was used


                      works great with Mac OS10.12.2