Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 3893 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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)

Posted
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
Posted

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.

Posted

Thanks for the warning comment.  Can you then tell me what the complete script would be.  Thank you.

Posted

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
Posted

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":

deleteme.jpeg

 

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

Posted

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.

Posted

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?

Posted

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.

Posted

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.

Posted

: )

 

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

This topic is 3893 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.