1 2 Previous Next 27 Replies Latest reply on Jun 10, 2013 9:29 AM by philmodjunk

    Scripting the Export and Import from Container Fields

    NaturSalus

      Title

      Scripting the Export and Import from Container Fields

      Post

           Hello,

           My current setup for passing data from version A to version B is first export all records from version A and then import them from version B. I use this approach instead of importing directly from version B because this has proven to be more reliable in my experience. However, I have noticed that I can't export the field contents from container fields.

            

           My Export  script has the Export Records script step where I add the fields that I want to export. I have noticed that if I add all the fields, including the container fields, save it and then open it to have a look at the fields listed: the container fields are missing!

           This must be the reason why I can't never pass the content of container fields from version A to version B.

           Is this an expected behavior?

           Is there a special way to script the export and import of the contents of container fields?

            

           Thanks,

           natursalus

            

           I have also noticed that if in the Export Records script step I add the container fields and save it and then I opem the Export

        • 1. Re: Scripting the Export and Import from Container Fields
          philmodjunk

               Yes, it's expected behavior. Files in container fields are files in their own right and thus cannot be exported to what is essentially a text file.

               But you should be able to import from and export to FileMaker files or you can use Export Field contents to filll a folder with individual files that can then be imported into your new file using Import Records | Folder. This second option will not work unless there is some way to use the files' names to import the data back into the correct fields of the new FileMaker file.

               It's not clear to me what you gain by exporting to an intermediary file like this instead of importing directly from A into B.

          • 2. Re: Scripting the Export and Import from Container Fields
            NaturSalus

                 Hello Phil,

                 Thank you for looking into my question.

                  

            It's not clear to me what you gain by exporting to an intermediary file like this instead of importing directly from A into B.

                 Basically because it works consistently in my hands. Whereas the importing directly has had unpredictable outcomes and turned out a nightmare for me.

                 As a matter of fact I tried to make it work with your help and others from another forum, sometime ago, but it didn't in my hands.

                 And when you reach the point that you can't make it work consistently whereas your peers tell you: "guy it's easy, it works". You feel crushed like an insect.

                  

            • 3. Re: Scripting the Export and Import from Container Fields
              philmodjunk

                   Nevertheless, it does indeed work and work quite well.

              • 4. Re: Scripting the Export and Import from Container Fields
                NaturSalus

                Nevertheless, it does indeed work and work quite well.

                      

                     Just for the record 

                     the "easy way" is importing trhough scripting directly from version B.

                     well when running the Import script using the Administrator account with full access privileges and when running the Import script with full access privileges I get the following interesting errors with the debugger:

                     Go to Layout ["A"]

                     Show All Records

                     Delete All Records [No dialog]

                     Import Records [No dialog; "versionA.fp7"; Add; Windows ANSI]  <------- Error 3

                     Sort Records [Restore; No dialog] <------ Error 714

                     Go to Record/request/Page/Last

                     Set Next Serial Value [A::A__kp; A::A__kp +1]   <---- Error 101

                      

                     As said before I have wasted countless hours trying to make it work but without any success. Had I found a way to export first container fields and importing them later I wouldn't be asking the same questions that I was 4 months ago.

                      

                     Concerning the Import Records script step I set it up first opening the source file (version A) with the Administrator account and then opening the target file (version B), then I do the field matching.

                • 5. Re: Scripting the Export and Import from Container Fields
                  NaturSalus
                       Stetp1
                  you can use Export Field contents to filll a folder with individual files
                        
                       Step2
                   that can then be imported into your new file using Import Records | Folder. This second option will not work unless there is some way to use the files' names to import the data back into the correct fields of the new FileMaker file.
                        
                       Although I implemented both steps since I don't know of any way to script the automatic import of exported files, this approach doesn't work for me.
                        
                        
                  • 6. Re: Scripting the Export and Import from Container Fields
                    NaturSalus

                         Since in none of my projects direct field importing is workable so far, I am forced to used the following approach:

                         For fields that are not containers, the user first export fields form version A and then imports then automatically from version B.

                         For container fields, the user imports them manually directly from version B.

                         Not  a fancy approach but it is the one that works for me using either FM11 or FM12.

                    • 7. Re: Scripting the Export and Import from Container Fields
                      philmodjunk

                           Natur Salus.

                           I frequently use scripted imports. In fact, one of mine does this every night and has for years through many versions.

                           Error 3: Command is unavailable (for example, wrong operating system, wrong mode, etc.)

                           That one is weird in this context. Normally, this error only appears when a file is developed in one version FileMaker and then run from an older version that does not have the specified command. An example would be using FileMaker 11 to add a script step newly added with 11 and then running the script in FileMaker 10. Don't see how that applies to an Import Records script step that has been part of FileMaker since the earliest days. What specific options have you specified for this step?

                           And I can't help wondering if one or both of these files might be damaged.


                           Error 714: Password privileges do not allow the operation

                           Since you are importing from one file to another, this suggests that you were unable to open the source file with a password/account that permits exporting records. There is a glitch in importing records that I've seen where Import Records trips a request for a password even though the target file is open with an account/password that exactly matches that of an account in the source file. Is there any chance that the source file was not already open? Try this script with that file open before running the script to see if that makes a difference.


                           Error 101: Record is missing

                           Since the previous errors indicate that no records were imported, this one is fully a logical result of that failed import--there are no records in the table and thus no way for this script step to be able to update the serial number settings.

                           

                                Although I implemented both steps since I don't know of any way to script the automatic import of exported files, this approach doesn't work for me.

                           If these are Image or text files, Import Records | Folder can be used to automatically import these files into a table. If these are files of other types, you can export the files to a folder inside your documents folder and then there is a get function that can be used with some parsing to get a list of the file names and file paths that can be used with a looping script and Import File to import all the files in that folder.

                           But I am not convinced that such a complex approach is necessary. The straight forward import from File A into File B should work--provided that they are both files of the same file format--both fp7 or both fmp12.

                      • 8. Re: Scripting the Export and Import from Container Fields
                        philmodjunk

                             Here's a zip folder with two demo files, FileASource and FileBTarget. There's a script in FileBTarget that imports all records from FileASource--including two picture files inserted into container fields.

                             To give it a try, frist extract both files from the zip folder so that they are uncompressed and then run the script in the target file. You can experiment with defiining accounts and passwords, but I don't anticipate that will be an issue as long as you have matching accounts/passwords defined in the two files with sufficient permissins to permit the scripts to run.

                        https://dl.dropboxusercontent.com/u/78737945/SimpleImportDemo.zip

                        • 9. Re: Scripting the Export and Import from Container Fields
                          NaturSalus

                                

                          Natur Salus.

                          I frequently use scripted imports. In fact, one of mine does this every night and has for years through many versions.

                               I never put in question your expertise on FileMaker.

                               As a matter of fact you are the one with enough knowlege to lead FMI forum.

                               Although I am not either a programmer or have background in database development I try to be factual when I write. Maybe it is a consequence of my past as a PhD in Molecular Biology.

                                

                          That one is weird in this context. Normally, this error only appears when a file is developed in one version FileMaker and then run from an older version that does not have the specified command. An example would be using FileMaker 11 to add a script step newly added with 11 and then running the script in FileMaker 10. Don't see how that applies to an Import Records script step that has been part of FileMaker since the earliest days.

                                

                               The Import script was created using FM11 Pro Advanced and has been tested both on FM 11 Pro Advanced and FM 12 Pro Advanced.

                                

                           What specific options have you specified for this step?

                               Source file: file:a.fp7

                               Import order:

                               Source: A  --------------- Target: B

                               Arranged by: matching names

                               Import Action: Add new records

                               Import Options: "Perform auto-enter options while importing", unselected

                                

                          Since you are importing from one file to another, this suggests that you were unable to open the source file with a password/account that permits exporting records. There is a glitch in importing records that I've seen where Import Records trips a request for a password even though the target file is open with an account/password that exactly matches that of an account in the source file. Is there any chance that the source file was not already open?

                               No, as I already pointed out before when I said:

                          "Concerning the Import Records script step I set it up first opening the source file (version A) with the Administrator account and then opening the target file (version B), then I do the field matching."

                                

                          And I can't help wondering if one or both of these files might be damaged.

                               Yes that could be a possibility. However, when I sent you a copy of my project , months ago, it worked in your hands but not in mine.

                               The Import script never worked. Even the first time that I tried it.

                               I have rewritten the Import script but no change.

                               I apologize for my candiness. But, where the corruption the cause of all my problems then:

                               Why using an account with restricted privileges I can export from version A all their fields but the container ones to a folder; and later I can import all thgose fields from version B using an account with restricted Privileges?

                               Why can I import manually from version B the container fields of version A?

                               Wouldn't you say tha a file corruption would pop up somewhereelse too?

                                

                               Just a side comment. The direct import of fields has been the most challeging task that I have faced with FM so far. I has never been able to make it work and I don't know why.

                                

                               As always, thanks for sharing your knowledge and your time. When I post a question I am not only looking for solution to my "problems" I also expect that your answers will be of help to others.

                                

                                

                          • 10. Re: Scripting the Export and Import from Container Fields
                            philmodjunk

                                 File corruption can be a very difficult thing to track down. I've seen files work perfectly on one OS version and crash on the other. I've seen files work just fine until the OS is updated to a new version or work fine until Filemaker is updated...

                                 All very frustrating, but also pretty rare.

                                 Did you try the demo files on your system? Did they work?

                            • 11. Re: Scripting the Export and Import from Container Fields
                              NaturSalus

                                   Hello Phil,

                                    

                              Did you try the demo files on your system? Did they work?

                                   Of course I tried them. And of course they worked.

                              File corruption can be a very difficult thing to track down. I've seen files work perfectly on one OS version and crash on the other. I've seen files work just fine until the OS is updated to a new version or work fine until Filemaker is updated...

                                   Yes probably that is my problem, but the project is so large that it would take me many days to create a new one. That is the reason why I am trying to save so many hours of work even through convoluted workarounds.

                                   I guess when you get old and "wiser" you have to limit the number of hours you can be in front of a monitor because your eyes  reclaim rest.

                                   I have been very close to dump FileMaker altogether. And I don't know if I'll work on my next project and check whetherthe direct import is possible there. But if it is not possible then that project will never see the light and I'll have to look for an alternative to FileMaker.

                                    

                              If these are Image or text files, Import Records | Folder can be used to automatically import these files into a table. If these are files of other types, you can export the files to a folder inside your documents folder and then there is a get function that can be used with some parsing to get a list of the file names and file paths that can be used with a looping script and Import File to import all the files in that folder.

                                   I have managed to export pdf files from container fields to the FmExport folder on the desktop and import them later on from version B.

                                   But believe it or not, I can't do the same thing with image (jpg) files!

                                   When I try I get an FM message saying that the contents of container fields can't be exported, but they can.

                                   I have tried to export pdf first, create a pause and then export the image (jpg) files, but that doesn't seem to work.

                                   I have tried just to export the image (jpg) files only, but I got the same error message.

                                   The export script for the images is the following:

                                   # Create the FMExport folder in the Desktop
                                   Send Event [ open document/application; Text: “cmd /c md FMExport” ]
                                   [ Bring application to foreground ]
                                   Pause/Resume Script [ Duration (seconds): 3 ]

                                   # Export Food Picture container field. This never worked!
                                   Go to Layout [ “Food_Detail” (Food) ]
                                   Show All Records
                                   Go to Record/Request/Page [ First ]
                                   Loop
                                   Set Variable [ $FilePath; Value:"file:" & Get ( DesktopPath ) & "FMExport/" & Food::FoodPictureID & ".jpg" ]
                                   Export Field Contents [ Food::FoodPicture; “$FilePath” ]
                                   Go to Record/Request/Page [ Next; Exit after last ]
                                   End Loop

                                   I have done a search on Google and have found many different ways to export image fields from container fields in FM but none of them seem to work in my project.

                                    

                                   Having said this, all the functionalities of my project work smoothly. The only remaining issue so far is first being able to export image files to the FMExport folder and them import from them.

                                    

                                    

                                    

                                    

                                    

                                    

                                    

                              • 12. Re: Scripting the Export and Import from Container Fields
                                philmodjunk
                                     

                                          But believe it or not, I can't do the same thing with image (jpg) files!

                                     

                                          When I try I get an FM message saying that the contents of container fields can't be exported, but they can.

                                     Not necessarily. If insert Object where used to insert the file (or drag and drop in windows/FileMaker 11) where used to put the image file in the container field, then Export Field Contents cannot export the file from the container field.

                                     I think this issue is why Insert Object and support for OLE is not an option in FileMaker 12.

                                • 13. Re: Scripting the Export and Import from Container Fields
                                  NaturSalus

                                  Not necessarily. If insert Object where used to insert the file (or drag and drop in windows/FileMaker 11) where used to put the image file in the container field, then Export Field Contents cannot export the file from the container field.

                                       I insert images using a two steps Insert Script

                                  Go to Field [A::Picture]

                                  Insert Picture []

                                        

                                  I think this issue is why Insert Object and support for OLE is not an option in FileMaker 12.

                                       Not related to your comment, but originally the project is created under FM 11 v3 and later on is passed to FM 12 v4.

                                       I have tried to export images to a folder both from FM 11 and FM 12, but I keep getting the FM message that container fields can't be exported (?). I wowul have expected an error, but such an explicit  message surprised me: It is as I was violating a fundamental principle related about how FM works.

                                       However, if I try to export each image manually using the script command: Export Field Contents. Specify target field: A::Picture, it works fine. This doesn't make much sense to me. Where the problems due to a corruption either in the Accounts or Privilege settings (this is one of my hypotheses) I would expect the same blockage when trying to export the image one at the time.

                                       I am open to try anything that comes to your mind to find out why exporting images to a folder is not working on my project.

                                       My workaround to this problem is that there will be no upgrades of my project. 

                                        

                                        

                                  • 14. Re: Scripting the Export and Import from Container Fields
                                    NaturSalus

                                         Hello Phil,

                                         It seems that the problem of exporting the images to a folder has nothing to do with Accounts or Privileges settings.
                                          
                                          
                                         If a try to export regular fields (not container) and container fields containing pdf files. No problem, pfds are exported to the folder.
                                          
                                         If a try to export regular fields (not container) and a container field containing an image. No problem, the images are exported to the folder.
                                          
                                         If a try to export regular fields (not container), container fields containing pdf files, and  a container field containing an image. The exporting of the pdf files is disrupted and nothing is exported into the folder
                                          
                                         If after exporting regular fields (not container) and container fields containing pdf files into a folder, I run another script that exports just the a container field containing the image, I get the message: "Container fields cannot be exported"
                                          
                                         Interesting...
                                          
                                    1 2 Previous Next