March 26, 201411 yr I have a very simple, single-table FMPro12 database, with text fields called 'quotation_html' and 'serial_number'. There are about 500 records in the table. What I need is a script which: -- for each record exports the content of field: 'quotation_html' as a tab-delimited file -- naming each file with the content of field: 'serial_number' for that record Therefore, I would finish up with about 500 files in a folder called 'desktop/quotes' each one named 1 to 500 (assuming that was the sequence of text in 'serial_number') Thank you to anyone who can help me by providing this script (MacOS 10.8.5)
March 27, 201411 yr Go to Record/Request/Page [First] Loop Set Variable [$path; Value:Get ( DesktopPath ) & "/quotes/" & serial_number] Export Field Contents [YourTable::quotation_html; "$path"] Go to Record/Request/Page [Next; Exit after last] End Loop
March 27, 201411 yr Beware of using Export Field Contents with text fields; the resulting file is UTF-16 encoded and not all applications know how to handle it. Preferably, isolate each record in turn in a found set of its own (using a new window) and export it as a tab-delimited file.
March 27, 201411 yr Author Thanks for the warning comment. Can you then tell me what the complete script would be. Thank you.
March 27, 201411 yr Untested: Show All Records Go to Record [First] Loop New Window [] Omit Record Show Omitted Only Set Variable [$filepath ; Get ( DesktopPath ) & "quotes/" & YourTable::serial_number & ".txt"] # export as tab-separated text, specifying quotation_html in the export field order: Export Records [ ... ] Close Window Go to Record [Next ; Exit after last] End Loop
March 27, 201411 yr Author Hi comment. I tried the following script - because I could not see a "Get" in the list of available script steps, instead of "Get ( Desktop Path )" I inserted the actual path which I obtained by clicking the "Add File" button after "Specify Output File": When I performed the script I got an error alert box saying: “ & quotations::serial number & ".txt"” could not be created on this disk. Use a different name, make more room on the disk, unlock it or use a different disk. (1) can you please correct my script for me (I had to paste it as an image because I couldn't work out how to copy-and-paste the script; I got a dialog with a box for pasting, but pressing Cmd-v in it didn't work!) (2) can we add a step enabling me to cancel the script (perhaps by pressing 'Esc' on my keyboard)? I had to hold down the 'Enter' key the whole time while the script failed 500 times!! Many thanks. Philip
March 27, 201411 yr 1. Get ( DesktopPath ) is not a script step; it's a function. 2. The error message you get indicates an invalid path. Which is not surprising, given the concoction you have cooked up. The value of $filepath should be calculated using the following formula: Get ( DesktopPath ) & "quotes/" & quotations::serial_number & ".txt" Note that there are no escaped quotes in this formula. 3. Testing a looping script is best done with a small found set.
March 27, 201411 yr Author Thanks comment. I have got it working now. Your comment (sic!) "3. Testing a looping script is best done with a small found set." is fair comment, but do you mean there's not a simple script-step to end the loop conditionally?
March 27, 201411 yr do you mean there's not a simple script-step to end the loop conditionally? Yes, there is - but what would the condition be?
March 27, 201411 yr That's not possible, because there's no way to express "the user is pressing 'Esc'" as a calculation formula (except when a script is triggered OnObjectKeystroke). You could, however, use Get ( ActiveModifierKeys ) to detect user holding down Shift, Option, Control or a combination thereof. In any case, pressing 'Esc' does abort a running script (unless Allow User Abort is off). But you must press it while the script is running. Pressing it when the script is paused (including for showing an error message) has no effect. Also, if you're serious about script debugging, consider moving to the Advanced version.
March 27, 201411 yr Author OK. Thanks for all your help, I now seem to have what I need. I suspected it was not possible, but thanks to your help I have now discovered that **holding down** the Esc key works.
March 27, 201411 yr Author : ) Not for several generations. I typed "Just a typo for textfile …. and then watched as my browser's autocorrect turned textfile into textile when I hit return!! I really **must** find the way to turn that off (I thought I had done). Anyway, thanks for all your help. I'll be back when I need some more! Regards, Philip
Create an account or sign in to comment