Saturday, January 08, 2005

FileMaker Relationship and Portal tips

Category: Mac, Category: FileMaker Pro

Originally posted on my iBlog 8 January 2005.

Summary: These are some notes on my first attempts to set up portals in FileMaker Pro 7. Don't treat this as gospel. I'm still playing with this stuff.

Body: Portals allow the many related records to be displayed in rows within a layout of the original table. The portal should contain fields from the related table. New records in the related table can be created in the portal if "Allow creation of records in this table via this relationship" is turned on in the relationship between the tables (in the Relationships graph of File:Define...:Database").

******************

To prevent a field from being altered in Browse mode (for example, if you want to only allow users to enter a value into the field using a script), in Layout mode, select Field:Field Behaviour... and turn off the option to enter in Browse mode. Keep the option to enter in Find mode.

In the NatureObserver (prototype name) project, I use this option to create new datasets for a datasource, inside a portal in a layout in the datasource table. This way, if the user deletes dataset 3 of 5, they are unable to renumber the remaining datasets manually. They are forced to live with a set of records with dataset numbers 1,2,4, and 5. This is essential for relationships not to be disrupted.

******************

Deleting a row from a portal (i.e., the related record in the related table is deleted) has a potentially dangerous twist. Keep the "Delete records in this table when a record is deleted in the other table" option turned off, unless you want to start a chain of related record deletions moving up the relationships.

When forming the relationships between tables in the database (and between databases), be very careful about setting the options to create and delete records in each side of the relationship from the location of the related record. You access these options when setting up a relationship, or by double-clicking on the page icon for a relationship between two tables on the Relationships graph.

I took some time to solve a mystery of why, when I deleted one dataset (of several from one datasource), I also mysteriously deleted the datasource record for that dataset and the full citation record for that datasource. This happened because FileMaker followed up a chain of selected "Delete records in this table when a record is deleted in the other table" options. It general, it is important to have this option always turned off. However, the reverse option, "Allow creation of records in this table via this relationship" can be very useful, and I am tending to turn it on by default. It is necessary for creating new records from within a portal.

******************

The following is copied from the file "ManyMany PortalScript", dated 4 January 2005

The following set of scripts moves from a portal row in Table 1 to the related record in a Join Table and then to the related record in Table 2. The next three scripts move backwards to the original portal row. Scripts applied from a description at http://dbforums.com/t349224.html.

This system of Table1-Join-Table2 is apparently the best way to set up a many-many relationship in FileMaker Pro (in effect, by fusing a many-one and one-many relationship). I'm still missing the step of how to extend this simple example (one-one-one) to the many-many situation.

These scripts are working in my trial database, PortalManyManyTest.fp7.

First
Set Field [ Table1::GlobalNumber; Get(PortalRowNumber) ]
Go to Related Record [ From table: "JoinTable"; Using layout: "JoinTable" (JoinTable) ]
Perform Script [ "Join" ]

Join
Go to Related Record [ From table: "Table2"; Using layout: "Table2" (Table2) ]
Perform Script [ "Second" ]

Second
Go to Field [ JoinTable::ID2 ]
[ Select/perform ]

And back again...

SecondReturn
Go to Related Record [ From table: "JoinTable"; Using layout: "JoinTable" (JoinTable) ]
Perform Script [ "JoinReturn" ]

JoinReturn
Go to Related Record [ From table: "Table1"; Using layout: "Table1" (Table1) ]
Perform Script [ "FirstReturn" ]

FirstReturn
Go to Portal Row [ Table1::GlobalNumber ]
[ Select; No dialog ]

******************
I have scripted the addition of new datasets in the portal in the datasource table layout, as follows.

"Add a new Dataset in same DataSource from DataSource portal"
Set Field [ DataSource::global number; 0 ]
Go to Portal Row
[ Select; Last ]
Go to Portal Row
[ Select; Previous ]
Copy [ DataSets::Dataset_number ]
[ Select ]
Paste [ DataSource::global number ]
[ Select ]
Go to Portal Row
[ Select; Last ]
Set Field [ DataSets::Dataset_number; DataSource::global number + 1 ]

Note that since I am allowing the creation of new records from within the portal, the last row is blank, for new record creation.

I didn't want the user to see the global number, so I removed the field from this layout. But then the script stopped working. It turns out that it must be on the layout of the script. So instead I changed its text to white (and no border) to disappear from view.

[In the end, this proved unsuitable, and I decided to use a unique per-record dataset ID, which is auto-entered when the user starts to enter data on the last (new) row of the portal.]

Thursday, January 06, 2005

Note to self: Periodically save compressed copies of my FileMaker databases

Category: Mac, Category: FileMaker Pro

Originally posted on my iBlog 6 January 2005.

Summary: I find out all sorts of things by accident (I'm not the manual reading kind of person). Hence tips like this one are things I stumble across and then gaze at in wonder.

Periodically save a compressed copy of the database. Then trash the original and rename the copy with the exact name of the original. After structural changes is a good time to do this. Otherwise, every few months. If the compressed copy is significantly smaller, it was time to compress. If there's little difference, then wait a bit longer before the next compression.

FileMaker Pro 7: wrestling with when File and System Date and Time Formats are different

Category: Mac, Category: FileMaker Pro

Originally posted on my iBlog 6 January 2005.

Summary: Like a lot of good software, FileMaker Pro is designed in the US. As such, it is built in a world of such wacky standards as US Letter page size and a date format that goes month/day/year. FileMaker databases seem to take on the date format of the computer on which they were built, which means US format for the default templates. As a kiwi who uses a sensible, hierarchical date format, this can cause a few problems. Here's how I get around this.

If you get a warning each time a database is opened, saying the system and file date and time formats are different, it is because the system settings on the computer at the time the database was created differ from the current settings.

For example, this has happened to me with FMPro databases I made while in the US but now use in NZ. I've discovered in FMPro7 (and it may apply to earlier versions also) that all the templates that come with the program were made in the US and so have the wacky US date system built in as their default. I get the warning every time I open such a file, which is hardly ideal! One fix, from FMPro Help, is to force the database to always adopt the System settings of the computer it is being opened on, without asking. To do this, Select File:File Options. In the Text window, there are options for Data Entry when current System settings differ from saved settings. Click to use "Always use current system settings".