13 Replies Latest reply on Dec 31, 2013 9:04 PM by NicholasFernandez

    Import records script returns file not found error

    NicholasFernandez

      Title

      Import records script returns file not found error

      Post

           Hi,

           In attempting to find a workaround for one problem, I seem to have created another.

           I wanted to write a script that would allow users to select any database from our records as the source from which to import records into the current database while ensuring that the import order of fields was predetermined. My research revealed that the only way to set the import order was by having the database from which the records are coming pre-selected. So I created a script that:

             
      •           Import records from a predetermined database
      •      
      •           Deletes these records immediately
      •      
      •           Then prompts the user to select the database from which they want to import records, using "last order" as the import order

           The script works fine, but it always returns an error message of "The previous script step, “Import Records”, could not be completed because of an error.  Do you wish to continue with this script?" (error number 100 – – file not found)

           Either half of the script works fine with the other part disabled, and whether the user selects "cancel" or "continue," makes no difference; the records are still imported correctly. However, the message will be disconcerting to many users and needs to be avoided.

           Any suggestions on how I could fix my script were simply override the warnings so that the user doesn't see it? (I've already tried setting air capture to "on.")

           Let me know if any additional information would help. Thanks!

      Screen_Shot_2013-12-22_at_11.11.31_PM.png

        • 1. Re: Import records script returns file not found error
          philmodjunk

               Try adding Set Error Capture [on]

               To the beginning of your script. This is the standard step for suppressing most error messages that would otherwise interrupt your script.

          • 2. Re: Import records script returns file not found error
            philmodjunk

                 There is, however, an alternate method for doing this:

                 Define a global container field.

                 Set up your script to use insert file to insert a file into it with the "store a reference" option enabled.

                 The user selects the file from which they want to import using the open file dialog that this insert step opens.

                 Then your script extracts the file path to the inserted file and sets a $Path variable to it.

                 Import Records can then refer to that $path variable and import the records without opening dialog for the user to select the file from which to import.

                 The key trick is to put two file references into the file reference dialog. The first reference is to the $Path variable. The second is a valid file reference to a file that is valid at the time you define the script step. You use this reference to set up the field mapping and other options so that the field mapping is successfully retained in the Import Records step.

                 For More on $Path variables and how to extract file paths from container fields, see: Exploring the use of a $Path Variable in Scripts

            • 3. Re: Import records script returns file not found error
              NicholasFernandez

                   Hi Phil,

                   Well that was simple! I was placing the Error Capture at the end (like a getchar call to capture the "\n" character.

                   As for the alternative solution, I'll have to study that tomorrow and see if I can implement it properly.

                   Thanks!

              • 4. Re: Import records script returns file not found error
                NicholasFernandez

                     Hi Phil,

                     The alternate method works wonders, but I appear to have stumbled upon a bug, and I was curious as to why this would occur:

                     If I select a database with no records for the import, the import goes exactly as expected and no records are added. However, on the next running of the script, it imports all visible records from the backup file that is not the variable file path without giving the user an option to select a new file.

                     I can work around this, but do you have any idea why this happens? It only happens once, and then on the next running of the script functionality returns to normal.

                     Thanks again!

                • 5. Re: Import records script returns file not found error
                  philmodjunk

                       I'd have to see your script. Doesn't sound like the insert file script step is set up correctly.

                       To post a script to the forum:

                         
                  1.           You can upload a screen shot of your script by using the Upload an Image controls located just below Post A Answer.
                  2.      
                  3.           You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here. (with this approach, you can get multiple script steps on the same line, please edit the pasted text by inserting some returns to separate those steps.)
                  4.      
                  5.           If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
                  6.      
                  7.           If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format.
                  • 6. Re: Import records script returns file not found error
                    NicholasFernandez

                         Hi Phil,

                         Here's the code:

                          

                           
                    •           Insert File [ * Start-Up DB::PU Database ] [ Custom title: "Select Database to Pick Up Records" ] [ Storage method: Reference ] [    Display icon ] [ Compression: Never compress ]
                    •      
                    •           Set Variable [ $Path; Value:If ( ValueCount ( ${* Start-Up DB}::PU Database ) > 1 ; Let ( F = ${* Start-Up DB}::PU DB Filepath ; "file:" & Right ( F ; Length ( F ) - Position ( F ; ":" ; 1 ; 1 ) ) ) ; ${* Start-Up DB}::PU DB Filepath ) ]
                    •      
                    •           Import Records [ Source: “$Path” OR “filemac:/Mac HD 1/Users/nicholasfernandez/Dropbox/Job Search/Jobs Part 4/Macmillan to Go/*NEW startup DB 2013.fmp12”; Target: “* Start-Up DB”; Method: Add; Character Set: “Mac Roman”; Field Mapping:… (deleted text for ease of reading)… [ No dialog ]
                    • 7. Re: Import records script returns file not found error
                      philmodjunk

                           "* " seems an odd way to name a table occurrence and note how doing so requires the use of ${    }--making your expression much harder to read.

                           I'd add an if step right after the Insert File step to check and see if the user canceled instead of inserting a file:

                           If [ Get ( LastError ) ]
                              Exit Script []
                           End If

                           What is the field definition for PU DB Filepath? There might be an issue there.

                           What you've described is what will happen if the computed file path set to $Path is not a valid file path. It's a good idea to move or rename the file used as the secondary file reference after your script is fully set up and working so that it can be mistakenly used as the source file for your import.

                      • 8. Re: Import records script returns file not found error
                        NicholasFernandez

                             Hi Phil,

                              

                             I'm not a fan of the naming conventions, but I'm also not in a place to make those changes (I'm a temp who just happens to care about the database...)

                             the error catch solution you offered doesn't let the script go into the first step if a database with no visible records is selected on the previous import -- meaning users have no way to select a databse.

                             I'll be able to post code tomorrow.

                              

                             Thanks!

                        • 9. Re: Import records script returns file not found error
                          philmodjunk

                               That will only happen if there is an error with the insert file step itself--such as clicking cancel instead of selecting a file to insert into the container field. It should keep the script from trying to import from the wrong file if no file was selected in the open file dialog.

                          • 10. Re: Import records script returns file not found error
                            NicholasFernandez

                                 Phil,

                                 Was this:

                            "It's a good idea to move or rename the file used as the secondary file reference after your script is fully set up and working so that it can be mistakenly used as the source file for your import."

                            supposed to say: 

                            "It's a good idea to move or rename the file used as the secondary file reference after your script is fully set up and working so that it can't be mistakenly used as the source file for your import."

                                 If not, I'm confused by this statement. 

                                  

                            • 11. Re: Import records script returns file not found error
                              philmodjunk

                                   You are correct, my fingers fell behind my brain and left out the 't . blush

                              • 12. Re: Import records script returns file not found error
                                NicholasFernandez

                                     ah, that makes a lot more sense.

                                     Tomorrow I get to try the script in the office. I'll let you know how it goes.

                                     thanks again!

                                • 13. Re: Import records script returns file not found error
                                  NicholasFernandez

                                       well, things are going well so far! I still have to do some testing with the importing of an empty database error, but I appreciate all of your help!

                                       Take care,

                                       Nick