9 Replies Latest reply on Apr 21, 2016 12:31 PM by anothersmurf

    Creation date of file in a container field

    anothersmurf

      I have a container field into which a PDF can be uploaded (by a user-activated script). I want to also have a date field which shows the creation date of the PDF.

       

      I do this with a FMP script that uploads the PDF and also does the following:

      1. Paste the clipboard to a throwaway field in the DB

      2. Call an Applescript to get the creation date of the PDF and copy it to the clipboard

      3. Paste from the clipboard into the date field

      4. Copy the original clipboard contents back to the clipboard from the throwaway field

       

      It works, but it's awfully ugly, since it uses Applescript and passes data via the clipboard. Does anyone have a better way (without resorting to plugins)? Before you say it: Getcontainerattribute() can only return a creation date for a photo, so that doesn't work here, even if I use Insert Image to upload the PDF.

        • 1. Re: Creation date of file in a container field
          vavo

          have you tried:

          GetContainerAttribute(sourceField; "created")?

          • 2. Re: Creation date of file in a container field
            patricia

            I am confused. are you trying to capture the date the pdf was created or the date it was added to the container field.

            360 Works has some wonderful plug ins that capture information relating to PDF documents which are stored in container fields

             

            patricia

            • 3. Re: Creation date of file in a container field
              anothersmurf

              I want the date the PDF was created. Yes, doable with a plugin, but I want to avoid the cost & deployment issues of plugins.

              • 4. Re: Creation date of file in a container field
                keywords

                As already suggested, a calculation field with GetContainerAttribute ( yourTO::yourField ; "created" ) will give you the earliest timestamp from the file in the container. This will only work, however, if one has been set in the file itself, which is not necessarily the case; if there is no date this will return "?". You would probably need to use something like:

                If ( GetContainerAttribute ( aaaaa::container ; "created" ) = "?" ;

                "not dated – " & Get ( CurrentDate ) ;

                GetContainerAttribute ( aaaaa::container ; "created" )

                )

                • 5. Re: Creation date of file in a container field
                  anothersmurf

                  Please see FileMaker's documentation for GetContainerAttribute. It states that the created attribute only works for photos. If I attempt to get the created attribute of a PDF, it returns ?. Of course if you've found a way around that limitation, I'd be happy to hear it.

                  • 6. Re: Creation date of file in a container field
                    erolst

                    anothersmurf wrote:

                    It works, but it's awfully ugly, since it uses Applescript and passes data via the clipboard.

                     

                    Using AppleScript in and of itself isn't that ugly – but overwriting the Clipboard surely is.

                     

                    Having said that, create a “throwaway“ (I prefer the wording utility … ) global field and write to it from AppleScript, à la

                     

                    Set theDate to ( your AS code to read the PDF date )

                    Tell application "FileMaker Pro Advanced"

                      set field "gUtility" of table "YourTable" to theDate

                    end tell

                     

                    Get the correct syntax from the FileMaker AS dictionary – I can never remember if it is field or cell, table or database (all of which are valid object types, just in different contexts …)

                     

                    You can also write into non-global fields, but I think they have to be on the current layout, or that is hampered by some other limitation …

                    1 of 1 people found this helpful
                    • 7. Re: Creation date of file in a container field
                      keywords

                      I accept your correction, but add a correction of my own. Under the heading Photos it adds: "Note  Only JPEG and TIFF files return results." I tested this and it is the case. In Photoshop I converted a jpg file into various other formats (PSD, PNG, EPS) none of which returned the Photo data that JPEG and TIFF files do, even though each is also a photo file format.

                      • 8. Re: Creation date of file in a container field
                        anothersmurf

                        That works, in most situations, and it's a definite improvement, thank you!

                         

                        One small change, I ended up using:

                         

                        "tell app \"FileMaker Pro" & If(contains(Get(ApplicationVersion); "Advanced"); " Advanced") & "\"..."

                         

                        since most of my users don't have Advanced. I've also sometimes seen Applescript tell the wrong version of an app, if a user has multiple versions installed: Applescript doesn't always choose the version that's running. I don't know how to deal with that, but it shouldn't impact my users (just me, since I keep old versions around for testing).

                         

                        It also, unfortunately, fails if a modal window is frontmost in FileMaker. If you've got a modal window, the Applescript times out. So it requires some window-juggling (open an identical non-modal window in the same location as the modal window, close the modal window, run the AppleScript, reopen the modal window, close the non-modal window... since FMP doesn't let you change modality of an existing window. Sigh.)

                        • 9. Re: Creation date of file in a container field
                          anothersmurf

                          OK, I found a way to do this without needing the Applescript to include a (possibly problematic) Tell FileMaker segment, and without using the clipboard.

                           

                          1. Turn error capture on.

                          2. Use an AppleScript to get the creation year of the file; return it as a negative error number.

                          3. Set a variable to abs(get(lasterror)).

                          4. Use an Applescript to get the creation month & year of the file; return that as another negative number.

                          5. Parse the variable and the latest errornumber together to make a date.

                          6. Set the field.

                           

                          The error number must be negative, or else the user will see an error message (despite error capture). Year and mo/day must be seperated because 8 digit error numbers produced by an AppleScript read as 0 when you get(lasterror).