8 Replies Latest reply on Oct 14, 2016 7:16 AM by mw777rcc

    Insert File from Temporary Path Works, but...

    deninger

      I have a simple script set up to export a PDF of the record, and then import it into a container elsewhere. Not that it matters, but the container is set to store externally on the server (secure).

       

      code snipped below:

       

      Print Setup [ Restore ; With dialog: Off ]

      Enter Preview Mode [ Pause: Off ]

       

      # create a file path in the temp folder naming the document with its UUID.pdf...

      Set Variable [ $fileName ; Value: "filemac:" & Get (TemporaryPath) & SOAP::soapID & ".pdf" ]

       

      # export the PDF to the path...

      Save Records as PDF [ Restore ; With dialog: Off ; “$fileName” ; Records being browsed ]

       

      # now navigate to the outgoing fax layout...

      Go to Layout [ “FaxLog” (FaxLog) ]

      Enter Browse Mode [ Pause: Off ]

       

      # create a new record and insert the document into the container

      New Record/Request

      # note that we are INSERTING the FILE, not simply recording a reference location.

      Insert File [ Insert ; Display content ; Compress when possible ; FaxLog::document ; “$fileName” ]

       

      This works like a charm. Well, sort of...

       

      After exit FM Pro, restart it and re-open the file I get a "The file cannot be found: <file_name_here.pdf>" in the container.

       

      Insights are welcome as I am completely baffled.

        • 1. Re: Insert File from Temporary Path Works, but...
          Vaughan
          There is no need to preface the path with "filemac:" when using Get( TemporaryPath ) function.
          Also, make sure the file name does not have any illegal characters, for macOS colons are illegal.
          --
          EDIT: oops I completely misread the question.
          --
          The temporary folder gets deleted at the end of each FMP session, so no surprise you get the error "The file cannot be found: <file_name_here.pdf>" because the file has been deleted. When putting the pdf into the container, make sure you INSERT the file and not use a REFERENCE. Your posted script shows you know to insert the file, but the script's behaviour suggests that it's inserting a reference.
          • 2. Re: Insert File from Temporary Path Works, but...
            mw777rcc

            If you are inserting the file and not just the reference make sure you have committed the record.  A normal shut down should do this but that is the only other thing I see other than storing it as a reference instead of actually inserting the file.

            • 3. Re: Insert File from Temporary Path Works, but...
              philmodjunk

              Make sure that the script hasn't raced ahead and is trying to insert the file before the PDF has actually been created. Try putting a pause/resume step between the save and insert steps. Start with an infinite pause, then, if that works, try using shorter and shorter pauses.

              • 4. Re: Insert File from Temporary Path Works, but...
                rouelf

                designer, just adding questions:

                 

                Noticed that you are appending “.pdf” to whatever is in then field SOAP::soapID

                 

                Question why use “Save Records as PDF” ? would that not automatically append the “.pdf” ?

                 

                Instead of “Save Records as PDF”, why not use “Export Records”, just a question !!

                 

                Is this script set to run when you restart the file ?

                • 5. Re: Insert File from Temporary Path Works, but...
                  deninger

                  The script step in question is simply:

                   

                  Insert File [ Insert ; Display content ; Compress when possible ; FaxLog::document ; “$fileName” ]

                   

                   

                  It does Work. The script is not unable to find the document (trying to insert before the PDF has been created). It is correctly set to INSERT the document. It just seems to be acting like a REFERENCE was created to the file (that eventually disappears from the temporary location). The real question is: WHY?

                   

                  As for the suggestion about Commit. This did not fix it, so...

                   

                   

                  I recorded the container attribute in the log file after it was imported using:

                   

                   

                  Set Variable [ $storageTypeAttribute ; Value: GetContainerAttribute (FaxLog::document ; "storageType" ) ]

                   

                  The log recorded: ==> container type: External (Secure)

                   

                   

                  so it would appear that the document is indeed inserted (the possible returned values are Embedded, External (Secure), External (Open), File Reference, Text.).

                   

                   

                  I exited FileMaker and re-opened it and the file. The document again shows "the file cannot be found: <file_Name.pdf>"

                   

                   

                  I am baffled. Is the real problem that the document in the External Secure Store is not being found?

                   

                   

                  As to the other comments and questions:

                   

                  With respect to filename: if I don't add the extension (but specify the filename) the Mac does not append the extension. Adding it manually makes my life easier.

                   

                  Save Records as PDF is used to create a formatted, ready to fax document. Export Records does not create a formatted PDF (if I am wrong about this, then I apologize, but I am fairly certain that it does not)

                   

                   

                   

                   

                   

                   

                  • 6. Re: Insert File from Temporary Path Works, but...
                    Vaughan

                    Is the secure storage saving to the temporary folder?

                     

                    Is the file hosted?

                    • 7. Re: Insert File from Temporary Path Works, but...
                      user19752

                      Very sorry for putting foolish question, are you sure about the <file_Name.pdf> is the same record you last saved?

                       

                      You can try another logging that using GetContainerAttribute (FaxLog::document ; "externalFiles" ), then compare the result to the error message.

                      • 8. Re: Insert File from Temporary Path Works, but...
                        mw777rcc

                        Sorry to ask something silly, but I am down to silly answers because I don't understand how this is happening to you either. :-) 

                         

                        The field is not set to global storage, correct?  (if the file is hosted it would matter)