13 Replies Latest reply on May 17, 2012 8:56 AM by philmodjunk

    Saving pdf to external NAS Drive

    millie

      Title

      Saving pdf to external NAS Drive

      Post

      Hi - hope someone can help.

      I am trying to set a script to save a uniquely named pdf to our external NAS drive. This has to be a generic path which can be accessed by any user connected to the NAS drive.

      I saw a previous post with this script:

      Set Variable [ $Path ; Value:  "file:" & Get ( DesktopPath ) & YourTable::FileNameField & ".PDF"]
      Save Records as PDF [Restore; no dialog ; "$Path" ; //specify the other options you need for your script here]

      I have adapted this and created the unique file name but I dont' seem to be able to make the Save Records as PDF path work.  Please can I check what script I should prefix the path to the file on the NAS drive with in order to make it generic?

      I saw from a previous forum post that $Path is to create and open a folder on mac OSX.  I need every user (on macs and pcs) to be able to save to a specific folder within the NAS drive.  The folder is pre-existing.

        • 1. Re: Saving pdf to external NAS Drive
          Sorbsbuster

          I would suggest you save a file of the intended name into the intended destination folder, then open the folder in Windows Explorer, and copy the full URL.

          Set your script to save the file (including the 'filename.pdf') to that literal pathname, as "file: <paste in here the URL you copied>".  If that doesn't work, stop there - you need to get that working first.

          Prove that works from a Windows machine.

          Then gradually replace each element of the full pathname with your calculation components, checking after each replacement.

          The example you quote just uses the variable $Path to build up the correct full pathname.  '$Path' will work in any environment - all that is different is the components that you set into the variable.

          Your only difficulty should be when you move to a Mac machine (or vice versa, if you started on Mac).  They both need to see the same pathname.

          • 2. Re: Saving pdf to external NAS Drive
            millie

            Hi Sorbsbuster

            Can I just check I understand you correctly? I set the script to save the file to the full URL path from my mac and it worked perfectly but from my mac only.

            So, you suggest then replacing each element of the full path with calculation components. This is where I am sketchy as I am not sure exactly what are the correct components to type in to create a variable path. Scripting language is quite new to me in this context.

            I have tried different ways of scripting the last bit of the script lin....

            Save Records as PDF [Restore; no dialog ; "$Path" ; //This is the bit I cannot get to work]

            I tried typing in "$Path" ; //$path\\Nasdrive\shared folder\saved folder

            I know this is incorrect but I am struggling to find the correct 'phrase' to type in here to create a variable path.

            Cheers

            • 3. Re: Saving pdf to external NAS Drive
              philmodjunk

              The path has to be valid for all users. That means they need to all see the same path when "mounting" the shared directory.

              If the file is stored on an "NFS server", they will also need both read and write access instead of just read access to this folder due to a bug in FileMaker specfic to NFS servers.

              In cases where you have both mac and windows clients, you sometimes need either two container fields or a special calculaition field set to return a container type. The calculation uses the path stored in the original container field to compute a path that is valid for the current user's platform.

              • 4. Re: Saving pdf to external NAS Drive
                millie

                Hi - I am still struggling with the exact wording of the script to use.  We are not storing on a server but just an external NAS drive which is connected via a network to all users (some of whom are working on mac and some on pc). 

                I have tried setting up 2 paths but just can't seem to get the script to work....

                • 5. Re: Saving pdf to external NAS Drive
                  Sorbsbuster

                  "I set the script to save the file to the full URL path from my mac and it worked perfectly but from my mac only."

                  That's a good star.  What did the pathname look like that you entered?  I am asking that because I am unfamiliar with Mac path names and I may invent a syntax that only causes confusion.

                  Okay: here goes anyway.  I think the pathname should read like:

                  filemac:/NASDrive/PDFsSavedFromFilemaker/test.pdf - if the volume mounted is called 'NASDrive' and has inside it a Folder called 'PDFsSavedFromFilemaker' where you want to store the pdf file called 'test'.

                  If that works for you (and it should, because you copied and pasted it from Finder, and you tried it and it works) then on your workstation (because it works) replace the components of the pathname one by one.  To introduce the use of $Path, set the script step becfore the export to be:

                  Set Variable [$Path ; "filemac:/NASDrive/PDFsSavedFromFilemaker/test.pdf" ]

                  Then have the script step
                  Save Records as PDF [Restore; no dialog ; "$Path" ]

                  This will save that file name.

                  Now work only with the script line for the $Variable.

                  Change it to be

                  Set Variable [$Path ; "filemac:/NASDrive/PDFsSavedFromFilemaker/test" & Get ( CurrentDate ) & ".pdf" ]

                  and you will see that it saves the file, but now calls it 'test' with the date appended.

                  You can set all the components (eg the final folder) to be calculations - maybe dependent on the logged-in user's name, they may store them in a different place, for example.  Or you may want to include something from the record (like a name or ID) in the file name.

                  If it breaks on other machines it will almost certainly be because their mounted volume is not the same name as the one you include in your script.

                  When that works try changing it to 'file' (not filemac') at the start and see if it still works.

                  Then you can think about adding a pathname like:
                  "filewin:/Z/PDFsSavedFromFilemaker/test.pdf"

                  if all windows users have mapped the NAS Drive to be their Z drive.

                  • 6. Re: Saving pdf to external NAS Drive
                    philmodjunk

                    file: works inplace of both filewin and filemac according to my experience with save as PDF.

                    There's a small, but critical typo in sorbsbuster's sample windows filepath. It should read:

                    filewin:/Z:/PDFsSavedFromFilemaker/test.pdf"

                    This can be tricky to set up as FileMaker doesn't tell you anything useful when you try this and get an error message. You don't know if there wasn't enough space on the drive, or if permissions didn't allow saving to that location or if the filepath was invalid nor why it might be invalid. Including a show custom dialog step as a temporary debugging step that displays the contents of your $path variable is often helpful in double checking for errors in the path.

                    • 7. Re: Saving pdf to external NAS Drive
                      millie

                      Thanks to Sorbsbuster and PhilModJunk - all sorted.

                      Your help is much appreciated.

                      • 8. Re: Saving pdf to external NAS Drive
                        millie

                        Hi there.  I have reopened this question as it seems that my file path will still only work on one platform.  If I set up on a pc, it works from there - or from the mac, but not on both at the same time. I have tried moving from one to the other and using the prefix 'file:' and it works individually but not if I then open the file on another computer!!!

                        In mind of PhilModJunk's comment:  'In cases where you have both mac and windows clients, you sometimes need either two container fields or a special calculaition field set to return a container type. The calculation uses the path stored in the original container field to compute a path that is valid for the current user's platform'.

                        I think that because the field $Path isn't picking up the file path on the pc and mac, then perhaps I need to set up a calculation field set to return a container type.  I am not sure how this works - can anyone point me in the direction of the right functions?

                        Many thanks for your help.

                        • 9. Re: Saving pdf to external NAS Drive
                          philmodjunk

                          Your go to related records steps don't look like they are set up correctly as they refer to the table occurrence that is the same as that specified for the Record Detail layout. You might want to check and see if you are on the correct record in each case.

                          Given that your path is "hard wired", it computes the path from literal text, and does not use a function, field or variable to produce the folder names, I'm suprised that this works the way you describe. I'd expect it to work either all the time on a given platform or none of the time. I don't see how "If I set it up on a..." would make a difference in how this path calculation would work any differently. What exactly do you mean by that phrase? What does "set it up on" mean?

                          The main difference in file paths for Mac in windows is that Macs usually have this pattern:

                          VolumneName / folder names/ filename

                          and Windows machines have this:

                          Driveletter / Folder names / filename

                          so you often have to detect what platform is current and compute the first part of the file path differently.

                          Note also that if this is a shared folder, different computers may be set up to map/mount the folder differently and this can affect whether a given file path to that shared folder is valid or not.

                          • 10. Re: Saving pdf to external NAS Drive
                            millie

                            Hi PhilModJunk - thanks for your reply.

                            Basically, I set up the specified path $Path on my mac using the 'add' button.  This path was then specified on the mac and did not work on the pc.  I mapped the same thing on the pc and it worked there but not on the mac.  I have tried working out a variable path but am obviously missing something essential.

                            The NAS drive where I need to save the pdf is a shared drive that is not mapped as a drive on most pcs.  Do I need to map this in order to make a variable path work?

                            Many thanks!

                            Muir

                            • 11. Re: Saving pdf to external NAS Drive
                              philmodjunk

                              Yes, each PC needs to map the the drive or shared folder in exactly the same way. The individual computer needs to be able to access the shared directory via the path used by filemaker to open the file.

                              This gets you to the point where you have one path for mac and one path for windows. Then you can use calculations that detect whether the current machine is mac or windows and returns the path that is appropriate for that operating system.

                              • 12. Re: Saving pdf to external NAS Drive
                                millie

                                In looking at the functions, I believe that in the calculation I need to set a script that can Get Platform and then choose a filepath based on results.  Does this sound feasible?

                                I am not sure of the scripting of the calculation though.

                                • 13. Re: Saving pdf to external NAS Drive
                                  philmodjunk

                                  Case ( Abs ( Get ( SystemPlatform ) ) = 1 ; /* put path for mac platforms here */ ;
                                            Get ( SystemPlatform ) = 2 ; /* put path for windows platforms here */ ;
                                            /*  you have an iOS device */ )

                                  The challenge will be in choosing a method for calculating your file paths. One option is to extract the file path from your container field and do the needed surgery on the first part of the path to make it either Mac or windows compatible. This assumes that your filepaths will be identical except for the first part of the path where you need either a drive letter or a volume name.

                                  For Files inserted with the Insert File method and with the "store a reference" option specified, GetValue ( containerField ; 2 ) will return the file path stored in the container. For files inserted with Insert Picture, use GetValue ( ContainerField ; 3 )