6 Replies Latest reply on Oct 26, 2014 11:55 PM by user19752

    Scripts: Create PDF then Insert into Container; for Local & Remote users

    dew119

      Needing your help. After 3 days, I'm pretty frazzled after trying so many variables with no success.

       

      QUESTIONS (as I understand it):

      1. How to get the remote computer to save PDF to the host's "Files" folder (so it can find it during the Insert" step)?

      2. How can I calc/edit the relarted/full paths so the script works for MAC users too?

      ISSUE: I do not have user's host/server info so I ned to be able to use "GET" functions to build a path variables. I saw Get(HostName), Get(HostIPAddress) and Get(FilePath) but so far have been unable to create a workable calc with those..

      3. How to modify paths for MAC usrs? differtn format/syntax?

       

      GOAL: When user clicks a "Create PDF" button, a script creates the PDF, then Inserts a link to the PDF in a Container field (External, Open storage).

       

      Scenario:: I need this script to work with single/local and multi-user/remote "ConnectionStates". My multi-file solution is used sometimes by Single-users (with Local path) and sometimes by small groups who network/logon remotely (some small groups use FMPro12-13; others use FMs12-13).

       

      The script below works for Local (single-user). But, when the file is hosted and the user logs on remotely, the PDF gets saved to the workstation's FMA12 folder. Then, the workstation can't find the file during the "Insert" step, because it goes looking it in the host's "Files" folder.

       

      Hoping you can help to clear my fog ... ;-)

       

      Diane

       

      SCRIPT: Create PDF, then Insert doc into Container (external, open storage)

      • Allow User Abort [ On ]
      • Set Error Capture [ On ]

       

      • #

       

      • Go to Layout [ “PDU Certificates to Educators” (Placements) ]
      • #
      • # 1 ---------------- Variable: FileName -------------------

       

      • Set Variable [ $filename; Value: If( not IsEmpty( GetRepetition( Placements::vEducID ; 1) ) ; // THIS HIDDEN 10-20-2014 and IsValid ( GetRepetition( Placements::vEducID ; 1 )) Year ( Placements::PL_EndDate ) & "-" & Case( Month ( Placements::PL_EndDate ) = "1" ; "01" ; Month ( Placements::PL_EndDate ) = "2" ; "02" ; Month ( Placements::PL_EndDate ) = "3" ; "03" ; Month ( Placements::PL_EndDate ) = "4" ; "04" ; Month ( Placements::PL_EndDate ) = "5" ; "05" ; Month ( Placements::PL_EndDate ) = "6" ; "06" ; Month ( Placements::PL_EndDate ) = "7" ; "07" ; Month ( Placements::PL_EndDate ) = "8" ; "08" ; Month ( Placements::PL_EndDate ) = "9" ; "09" ; Month ( Placements::PL_EndDate ) = "10" ; "10" ; Month ( Placements::PL_EndDate ) = "11" ; "11" ; Month ( Placements::PL_EndDate ) = "12" ; "12" ) & "-" & Case( Day ( Placements::PL_EndDate ) = "1" ; "01" ; Day ( Placements::PL_EndDate ) = "2" ; "02" ; Day ( Placements::PL_EndDate ) = "3" ; "03" ; Day ( Placements::PL_EndDate ) = "4" ; "04" ; Day ( Placements::PL_EndDate ) = "5" ; "05" ; Day ( Placements::PL_EndDate ) = "6" ; "06" ; Day ( Placements::PL_EndDate ) = "7" ; "07" ; Day ( Placements::PL_EndDate ) = "8" ; "08" ; Day ( Placements::PL_EndDate ) = "9" ; "09" ; Day ( Placements::PL_EndDate ) ) & "_PDUs" & "_" & GetRepetition( Placements::PDU_Earned ; 1) & If( GetRepetition( Placements::PDU_Earned ; 1) < 2 ; "Unit_EDUC " ; "Units_EDUC " ) & GetRepetition( Placements::EducLName_LkUp ; 1) & "_" & TrimAll ( Placements::CenName_LkUp ; 3; 3 ) & "_STU " & LeftWords ( Placements::StuLNameF_LkUp; 1 ) & ".pdf" ; "" ) ]
      • #
      • # 2 ---------------- Variable: FilePath -------------------

       

      • If [ Get ( ConnectionState ) < 1 // LOCAL, Single User ]

       

      • Set Variable [ $filepath; Value:"file:Files/Placements/$filename" ]

       

      • Else If [ Get ( ConnectionState ) > 0 // NETWORK, Remote User ]
      • Set Variable [ $filepath; Value:Get(FilePath) ]

       

      • End If
      • #
      • # 3 --------------- Variable: FilePathName -------------------

       

      • If [ Get ( ConnectionState ) < 1 // LOCAL, Single User ]
      • Set Variable [ $filepathname; Value:"file:Files/Placements/$filename" ]
      • Else If [ Get ( ConnectionState ) > 0 // NETWORK, Remote User ]

       

      • Set Variable [ $filepathname; Value:Substitute ( Get(FilePath); ".fmp12" ; "" ) & "/" & $filename ]

       

      • End If

       

       

       

      • #
      • # 4 --------------- SAVE RECORD AS PDF ..........................1 page ... [Restore; No dialog; FileName: (Variable) "$filename"; Current record]
      • If [ Get ( ConnectionState ) < 1 // LOCAL, Single User ]
      • #--------------- 10/20 9:43AM Step below worked LOCALLY ... but remote/networked user could not locate file for INSERT----------------------------------------
      • Save Records as PDF [ File Name: “file:Files/Placements/$filename”; Automatically open; Current record ] [ Document - Author: Placements::PDU_IssuedBy; Keywords: "PDU Certificate"; Compatibility: Acrobat 5 and later ] [ Pages - Number Pages From: 1; Include: Specific Pages; Start Page: 1; End Page: 1 ] [ Security - Printing: High Resolution; Editing: Any except extracting pages; Enable copying; Enable Screen Reader ] [ Initial View - Show: Page Only; Page Layout: Single Page; Magnification: 75% ] [ Restore; No dialog ]
      • Else If [ Get ( ConnectionState ) > 0 // NETWORK, Remote User ]
      • #--------------- 10/20 3:23PM Step below - REMOTE crated PDF and saved it to it's lovcal FMA12 folder ... Then, REMOTE unable to locate file for next INSERT step -----------------------

       

       

      • Save Records as PDF [ File Name: “$filename”; Automatically open; Current record ] [ Document - Author: Placements::PDU_IssuedBy; Keywords: "PDU Certificate"; Compatibility: Acrobat 5 and later ] [ Pages - Number Pages From: 1; Include: Specific Pages; Start Page: 1; End Page: 1 ] [ Security - Printing: High Resolution; Editing: Any except extracting pages; Enable copying; Enable Screen Reader ] [ Initial View - Show: Page Only; Page Layout: Single Page; Magnification: 75% ] [ Restore ]
      • End If
      • #
      • Go to Layout [ original layout ]
      • #
      • #
      • # 5 ------------------ INSERT new PDF into PlaceCNTR_PDUs ------------
      • #INSERT FILE: Store Reference ONLY (External storage): PATH: file:Files/Placements/$filename
      • If [ Get ( ConnectionState ) < 1 // LOCAL, Single User ]
      • Insert File [ Placements::PlaceCNTR_PDUCertificates; “file:Files/Placements/$filename” ]
      • #
      • Else If [ Get ( ConnectionState ) > 0 // NETWORK, Remote User ]

       

       

      • Insert File [ Placements::PlaceCNTR_PDUCertificates; “file://Files/Placements/$filename” OR “$filepathname” OR “file://$filepathname” OR “$filename” OR “file://$filepathname” ]
      • End If
      • #
      • Commit record.
      • -----------

      END

        • 1. Re: Scripts: Create PDF then Insert into Container; for Local & Remote users
          keywords

          Have you investigated using the Get ( TemporaryPath ) function? The beauty of that is that FM handles setting the path, it will always know where it has stored and exported file, and it will destroy the whole thing when the session ends, so you are not leaving PDF files lying around on various workstations.

          • 2. Re: Scripts: Create PDF then Insert into Container; for Local & Remote users
            dew119

            Thanks for your reply.

             

            I have explored your suggestion to use "Get(TemporaryPath)."

             

            It appears that using Get(TemporaryPath) will not work for me because I need to save the PDF to the server/host folder and store a link in a Container field (with External, Open storage) so that any user in multi-user groups may access/view the PDF.

             

            The Get(Temporary Path) saves the PDF to the local user's tempfolder and not to the server'host's Files folder, as desired.

            And, subsequently, the container data shows as "File not found" on other user's view and the PDF can not be accessed by other users via my "Open container" script because the container field's relative path is set to: "[databaselocation] Files/Placements" (by default) and the PDF is not saved to that location whenGet(TemporaryPath)" is used.

             

            I need more of your knowledge and experience, please ... 

               1. How can I script:  "Save as PDF" and "Insert" PDF into Container in a multi-uer setup

                    so that all users have access to the Container's PDF reference?

               2. How do I resolve the conflicting paths in the Container field  and the Save asPDF" and Insert File" script steps?

               3. Is there some less nightmarish way of accomplishing this task? 

                   I've read many posts about this and none seem to have definitive answers.

             

            Thanks, in advance.

            Diane

            • 3. Re: Scripts: Create PDF then Insert into Container; for Local & Remote users
              keywords

              Sorry, I misunderstood the task. Nevertheless, you could still use the temporary path for the first stage, creating the pdf file.

               

              If you are using FM's default location for the external storage of the container data the second part, inserting the pdf into the container you need a variant of your filepath. In "Save Records as PDF [ File Name: “file:Files/Placements/$filename" switch "file:" to "image:". For that reason when I set the path as a variable I create the two variants, thus:

               

              Let( [

              mainpath = Get (TemporaryPath ) OR <whatever path you wish to define> ;

              name = <tablename::fieldname> OR <whatever> ;

              <any other internal variables you want to define> ;

              extension =  ".pdf" ;

              $filepath = "file:" & mainpath & name & extension ;

              $imagepath = "image:" & mainpath & name & extension ] ;

               

              $filepath & "¶" & $imagepath )

               

              That calc allows you to use $filepath for export (ie. to create the pdf) and $imagepath for import *ie. to insert the pdf into a container.

              • 4. Re: Scripts: Create PDF then Insert into Container; for Local & Remote users
                user19752

                I need to save the PDF to the server/host folder and store a link in a Container field (with External, Open storage) so that any user in multi-user groups may access/view the PDF.

                Storing link to external open storage is meaningless (or advanced usage).

                You don't need store link, use container as 'interactive content' to show PDF in FM layout,

                or export field content to TemporaryPath and auto open it with another applications.

                (first keywords' suggestion)

                 

                Set Variable [$path; Value:Get ( TemporaryPath ) & $yourFilenameOfPDF]
                Save Records as PDF [Restore; No dialog; “$path”; Records being browsed]

                use here as 'file:$path'

                 

                if you use container field as 'Interactive content'

                Insert PDF [“$path”]

                use here as 'image:$path'

                 

                if you use it as 'Images' ( this titie in inspector is a bit confususs that on Windows PDF is not a image format, and any file other than image is insertable. )

                InsertFile ["$path"]

                use here as 'file:$path'

                 

                Absolute path is one of relative path, so this works on both Mac and Windows.

                 

                'conflicting paths' is automatically resolved by External storage that adding suffix to filename.

                You don't need care of what path is used whether the file is local or hosted, if you don't store link.

                • 5. Re: Scripts: Create PDF then Insert into Container; for Local & Remote users
                  dew119

                  Thank you very much for you replies.

                   

                  I wanted to post a reference to the article below which helped me find a successful path through the many variables.

                  Storing container field data externally (Answer ID: 10244)

                  http://help.filemaker.com/app/answers/detail/a_id/10244/~/storing-container-field-data-externally

                  • 6. Re: Scripts: Create PDF then Insert into Container; for Local & Remote users
                    user19752

                    Do you mean 'resolved' ?

                     

                    The article says

                    'However, they will still have the option "stored by reference." This is different than external storage. A database can have External storage configured, but if an end user selects "stored by reference," the file will be inserted just like it would be if the action had been done in versions pre FileMaker 12.'

                    This is that I said as 'meaningless'. You don't need external storage if you store reference in it.