0
votes

I have an Pro 13 database with around 120 records (it's for a conference). I want to team it up with BBEdit to create individual files for each abstract, thus . Much to my surprise (and despite a lot of web tips on scripting) '[tag:current record]' is not recognised in the script.

The relevant bit is this:

FM Script:
Loop
Perform Applescript

tell application "FileMaker Pro"
activate
set MyFileName to cell "WebAbstractFileName" of table "SelectionProcess"
set MyWebAbstract to cell "WebAbstract" of table "SelectionProcess" as text
end tell

-- (BBEdit bit, which works fine in testing)

 Go to Next Record (exit after last)
End Loop

This works fine if I only want to retrieve the first record!

This applescript is set within a filemaker script which loops through the records but the script doesn't care which record it's in.

I've tried adding 'of current record' before the table reference but it then gives me errors (eg error "FileMaker Pro got an error: Object not found." number -1728 from cell "WebAbstractFileName" of current record of table "SelectionProcess") Without 'current record' it works fine, but only gives me the first record.

4
You do realize you could accomplish this in Filemaker itself, by isolating each record in turn (in a new window) and exporting it? - michael.hor257k
+1 to michael.hor257k comment. Not only the first part could be done easier in FIleMaker, the second part posted below could be done in FIleMaker with no BBedit involvement. The only advantage I can see if ophiochos is more comfortable with AppleScript than FileMaker - Nicolai Kant
I wondered if Filemaker could create the files but wasn't sure how to ensure the right encoding and suffix. Ironically, we've decided to use a single file rather than my multiple ones so I'd be interested in how FM could do it as one day I want others to use the database -- any hints appreciated (Export record seemed to want to point at an existing file). The Applescript step that you both rightly point out is much easier within FM was needed to pass the variables to BBEdit... And yes, Nicolai, you guessed right -- I have much more experience of Applescript;) - ophiochos

4 Answers

0
votes

More tinkering solved this. The crucial bit was to change the syntax. The script now reads:

tell application "FileMaker Pro"
activate

tell current record to set MyFileName to cell "WebAbstractFileName"
tell current record to set MyWebAbstract to cell "WebAbstract"


end tell

What seems to happen is that the fields must be visible (yet I had that not be a problem at one point...go figure. If they're visible, you can drop the table specification). This script, wrapped in a Loop block, will act on the found set and (if instructed) exit after the last record.

I append the script to create a new file and save it with a variable taken from another field in case it's of interest.

tell application "BBEdit"
set notesPath to ":Users:ophiochos:Dropbox:TL Conference Admin:Webpage materials:Abstracts:"

set newFilePath to notesPath & MyFileName & ".html"

set newDoc to make new text document with properties {contents:MyWebAbstract}

tell newDoc
    set source language to "HTML"
    save to newFilePath
    close window
end tell
end tell
0
votes

Here's (roughly) how you could do this in a Filemaker script:

Go to Layout [ “YourTable” ] 
# FIND THE RECORDS OF INTEREST
Perform Find [ Restore ] 
Go to Record/Request/Page [ First ] 
Loop 
    New Window [  ] 
    # ISOLATE THE CURRENT RECORD
    Show All Records 
    Omit Record 
    Show Omitted Only 
    Set Variable [ $path; Value:Get ( DocumentsPath ) & "someFolder/"  & YourTable::Somefield  & ".html" ] 
    Export Records [ No dialog; “$path” ] 
    Close Window [ Current Window ] 
    Go to Record/Request/Page [ Next; Exit after last ] 
End Loop 

This will export every record in the found set as an individual file into the folder "someFolder" located in the user's Documents folder, using the contents of the YourTable::Somefield field as the filename.

If, as you say, you don't need the separate files, then of course this can be much simpler.

0
votes

Or you could simply create a calculated field that contains the contents of the desired export file for each record, loop through the records one by one, and just use an Export Field Contents ['YourCalculatedField_c'] script step.

0
votes

You can also use FM to preview the html output by using a web viewer to display your html. This, along with exporting individually, you can get all this functionality without the need for an external program.

If you need to change the text encoding for output files, you can also specify those in an xslt for outputting files: http://filemakerhacks.com/2012/09/23/export-field-contents-as-utf-8/

Also, if performing applescript from within FileMaker, the "tell application" line is not needed since it is implied.