October 4, 200718 yr Hi, I'm writing a script called Import Entire Database which essentially empties all tables and then fills them from a backup. The backup was created by the File>Save a Copy As... command. The script looks like this: [Empty all my tables first] // Do the following for each table Go to Layout["Customers" (Customers)] Import Records[No Dialog; Add; MacRoman] The layouts are each defined in Layout Setup to show records from the table I want to import into (i.e. my newly-emptied table). The Import Records step does not specify data source (I want to be prompted for that) but it does specify the import order. To do that, I gave Import Records a "sample" backup as a data source, then brought up the Specify Import Order dialog and set up the mapping (it's just "matching names", obviously). Finally, I clicked Perform without dialog and unclicked Specify Data Source. At runtime, I'm prompted to locate the backup file, after which the records are imported, for the first two or three tables. Then, suddenly, Import Records uses the wrong Source table! Of course, that's the end of that. I don't see what's different about this table. The database I'm attempting to load into is structurally identical to the one I'm trying to load from. If anyone can guess what might be wrong, or (better) suggest a different way to do this, that doesn't have to prompt me for the location of the source file for each table, I'd appreciate it. Thanks, Chap
October 4, 200718 yr put a routine before the import that asks the user to find the source table. then save that path into a global. use the global in the import script.
October 5, 200718 yr Author I've never been able to figure out how to do that. I think what you're suggesting is to use a script step (e.g. Import Records) that puts up a dialog box that allows the user to navigate through the file system and locate a file, followed by another script step that obtains the path of the file that was chosen. If there's a way to do that, I'd love to know it. (FWIW, I'm still on FMP8)
October 9, 200718 yr Author Sort of answering my own question here - but since there is a $48 plug-in (the 24U SimpleFile plugin) that puts up an Open File dialog or the Windows equivalent thereof, and return the path of the file or folder selected, I'm guessing it's not possible without the plug-in.
October 17, 200718 yr Author Returning to my original problem: I'm attempting to restore a database from a "backup" that was created with Save A Copy As...[copy of current file], but I'm having a hard time making the Import Records script step remember its Source Table when I do not specify the Data Source. For each table being imported, the table names are the same, as are the number and names of the fields. Yet sometimes, the Import Records script step forgets what Source table it's to pull from, choosing a different one, seemingly randomly. Is this a consequence of not specifying the Data source in the script step, in order to be able to choose it using the Open dialog at run time? Or should I be able to make this work somehow?
October 17, 200718 yr Import the source file into a container as a reference. You'll have the path now. Set that path to a variable, "$importSource" and use that as your import file in the import script steps.
October 18, 200718 yr Author Thanks... I've been trying to understand your suggestion, without success. Could you perhaps elaborate? I can't find any way to import a file into a single container field. I can insert a file into a container field (presumably this creates a reference), but I don't know how to obtain the path. If you would provide a few more details / script steps, it would be very helpful to me. (Again, FWIW, this is FMP8.)
October 21, 200718 yr My apologies, trying to reply w/o FM open. Yes, it's Insert File into a container (named gImportFile). Set Field [TO::gImportFile = ""] Insert File [Reference; TO::gImportFile] Set Variable [$SourceFilePath=GetAsText(TO::gImportFile)] Set Variable [$SourceFileName= Let ( posBackSlash = Position ( $SourceFilePath ;"/"; Length ( $SourceFilePath); -1) ; Right ( $SourceFilePath ; Length ( $SourceFilePath) - posBackSlash ) )] Then I use If/End to check that the $SourceFileName is an allowed entry.
October 21, 200718 yr Author Great! It works like a charm. Thank you very much for a solution that will come in handy a lot. For the archives, I would add: make sure that TO::gImportFile is on the current layout, or the Insert File step will silently fail with Error 102. (That's true of the other "Insert ..." steps, too, but I forgot since I try to avoid Insert for exactly that reason ;-)
Create an account or sign in to comment