Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Script to save field-content as textile named for another field

Featured Replies

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)

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

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.

  • Author

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

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

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

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.

  • 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?

do you mean there's not a simple script-step to end the loop conditionally?

 

Yes, there is - but what would the condition be?

  • Author

The user clicking 'Esc' on their keyboard.

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.

  • 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.

Good. Now what's the "textile" thing in the title? Are we in the rag trade now?

  • 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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.