Scripting a split in Filemaker database

I would like to split a FileMaker database so that the content of a standard selected field in every record will becomes the filename of the new database. The database has 660 records. Filemaker scripting possibilities do not allow me to copy the name of a field and make a clone of that databse just pasting the value from the clipboard in the dialogue box as a new name for the database.
Applescript does not allow me to create database fields …
I am stuck here.
Specifically I need to sort my db as I have 5 different majr categories. After sorting I’d ike to run a script which will create a number of new db where the filename is copied form one of the fields in the main database. This should be a loop or simlar.
I will need to use 5 different templates as only the basic fields are the same for each database, and the others I quite different.
How to tell Applescript wich tamplate to use?

What to do?

Tried Applescript but I am to omew to this all and I didn’t get very far.

I would be just happy if I could fill up the dialog box asking for the name of the db to create with the content of the clipboard. But I cannot do this , not even manually -…

Thanks really in advance

Ironically, I don’t think having Filemaker create the database is the best way of going about this.

The easiest way to do it is to have the template databases on disk and have the Finder duplicate the files, renaming them accordingly. The hardest part is knowing which template to duplicate for each record.

I’ll assume for now there’s a ‘name’ field in the database which defines the new database name and a separate field that stores a number from 1 to 5 indicating which of the 5 templates it should be based on. On that basis, the following script should get you well on the way:

-- source and destination paths
set sourceDir to "path:to:templates:"
set destDir to "path:to:new:databases:"

-- names of the template databases
set templates to {"template1.fmp", "template2.fmp", "template3.fmp", "template4.fmp", "template5.fmp"}

tell application "FileMaker Pro"
    -- find how many records there are
    set numRecords to count of records in database 1
    -- iterate through them
    repeat with i from 1 to numRecords
        -- get the record
        set thisRecord to record i of database 1
        -- extract the relevant field data
        set newDB_name to cell "database name" of thisRecord
        set newDB_template to item (cell "template name" of thisRecord) of templates
        
        tell application "Finder"
            -- make a copy of the template database
            set newDB to duplicate file newDB_name of folder sourceDir to destDir
            -- and change its name
            set name of newDB to newDB_name
        end tell
    end repeat
end tell

(standard disclaimer regarding error checking, etc. applies)

Almost every time I see a request like this (about FileMaker, and databases in general), the problem could better be solved by creating separate pieces of information in a couple databases, rather than creating many databases. What is it you are trying to do here? There may be a way that will let you accomplish your task more quickly, and more accessibly. Having that many FileMaker databases makes accessing your data very hard. Trust me - I’ve had to do data conversion many times when called in to consult.

If you post your FileMaker situation here, I doubt any AppleScript purists will complain. :slight_smile:

Thank you for your help. I know at first it sounds crazy creating so many databases but it’s the only way to solve my problems.
I teach Film at the University in Taipei. All my students fallow different topics and have different kind of requests and the original database where I tired to keep all my data became tremendously large and crashed many times.
However the central problem is about text encoding conversions. Some people wirte to me or submit the request in English. Tha vast majority write to me in Chinese. Chinese is not Mac friendly or Apple did not find yet a proper way to treat 2Bytes enchodings.
Traditional Chinese has several different encodings (BIG5, HKS, GB and more).
I am now using Powermail as all other mail programs do not read everything. Also Powermail allows me export to tab-delimited automatically.
I need to deal differently with each student as they follow different programs and submit different topics and there is no way to create that many different fields in the main database.
Also the Far East is more tech oriented than anything else I have ever seen in the west and everything happens through the net.

Thnak you so much

please visit my web site if you want

www.filmex.ws

Sorry … but all I know about apple script is turn the recorder on. I can’t get the script to work as I get this error message:
Filemaker pro got an error: object not found.
In my original database, the field which should become the new db copied title is “code”, and I created a number only field called “template name” numbering each record according to where it should go, however I also copied all the “code” fields to a new field called “database name” as in the script you kindly suggested me.
I changed the “template.fmp” to “template.fp5” as this is the extension for Filemaker 6 which I am using now.
The script returns exactly the number of records but then it igves an error when it has to execute the

set thisRecord to record i of database 1

is there anything I should do in the data base or in your code?

I created the 5 template files and put them in the same foder as the original database each template with the same 2 fields I need from the original big file and the other fields different for each of them.

What should I do?

Thank you from Taiwan

Well, it depends. Based on your previous post, it sounds like you are storing video clips in FileMaker databases, and that is why the files got so big. Is that correct? Also, I am not very familiar with 2-byte languages, but my understanding is that Mac OS X has far better OS-level support for them than most other OSes. Now, that does not mean that individual applications have taken advantage of that, so perhaps that is what is causing problems: apps that don’t handle 2-byte languages well.

Could you describe what kind of information you are storing in FileMaker? In other words, each record is unique in what way: is each record a student, a message, a film, or what? Perhaps there is a way to store what you need without using so much space.