|
|
|
Navigate: | My Mac Online | The Archives | April 2000 | FileMaker 101 - Part 25 | |
![]() |
|
![]() Part 25
My Mac Magazine manavesh@mymac.com
Multi-Key Value List Window One of the under-documented features of FileMaker Pro is its ability to use separate entries in a field as if they were actually separate records. Combined with relationships, this unlocks the power of many-to-many linking, without even having to use a join file. In fact, a few otherwise knowledgeable writers have criticized FileMaker for not having this ability, when it fact it does; it's just hidden. The entries have to be separated by paragraph returns, which is only allowed in text type fields (incl. global text fields), and there is the usual text limit of 64,000 characters. It is almost as if the multi-line field becomes its own little file. If a relationship is created, relating it to a field in another file, all records matching any of the lines within it will be matched. If it is related to a field within its own file, a "self-relationship," it will also match any record when the related field matches any of the lines. I use "multi-line" or "multi-key" for it, rather than "multi-valued," as the latter means a field that has many values (too many) but they are on the same line, like "John Smith, 121 E. St., Maplethorpe, Kentucky." The limitation of this multi-line feature is that it is not its own little file. So it cannot have auto-entered serial number IDs, and other necessities for serious data integrity. It's just a field, and it's up to you to populate it. But it has its uses.
The most common use for a multi-key field is to put the different IDs from several records into a global field, then use that to match records. An example of this would be the famous Copy All Records operation. I've written about it before, so I won't say much now. See my "Import" example file for a detailed look.
This time though, I'm not going to do that. I'm going to put the IDs from one file into a regular field in another file. In this case I'm not going to have just one ID, to match one ID in the other file; I'm going to add several ID values, one at a time, with paragraph returns between them.
There need be no direct relationship between the file from where the IDs originated and the file with the multi-key. The whole purpose of the structure is to filter the records in one of the files in an indirect way, when it isn't possible to do so in a direct way.
Many-to-Many In other words, there can be many different IDs from another file in the multi-key field; it can be different in each record; there can be the same ID in several different records, along with any combination of other IDs. Yikes. Useful, though.
What I am using it for is to keep a list of choices that would normally be unavailable to the file the multi-key is in. It is doing the work of an extra join file, in a file that is already a join file.
Example Files The problem is in data entry. I would create the new event from the People file, or duplicate a previous event in the Events file. In both cases, the event knows who the person is. But the store must be chosen.
It's easy enough to have a list of all the stores. But what if a person is shopping often at the same store, or a few stores, and there are a lot of stores.
Storess file But how does the Storess file know which stores the person has shopped at, since there is no connection between the People file and the Storess file?
There are two or three ways to do this. The first would be to use the Copy All Records routine in the Events file. Each entry in that file has both a Person's ID and a Store's ID in it.
Multi-Keyed People The method that I use in the example file is somewhat similar in principle. But rather than having to go to all the Person's records in the Events file and paste into a temporary global field, I store the Person's ID in a regular field in the Storess file. Every time a store is chosen for the Events file, that Person's ID is brought over and added to the multi-key field in the Store's record. It could be the same person, it could be a different person. I name the multi-key field, "People IDs". Even if the rest of the name were the same, the ending "s" makes it visually different from the Person ID field, which is in the other files. I do, however, use the "People ID g" global field interchangeably, as it's just for temporary use and can hold either one or many lines. The Person ID value is passed to the Storess file in a global field via a Constant::Constant relationship. This needs no other relationship, since a global is the same for all records, and the Constant value is the same for all records.
Triggering the List of Stores
There is a relationship between the Person's ID and the multi-key field with People's IDs in Storess.
There is a "New" button at the top of the little list, so it's quite easy to add a new store, hopefully after checking that it doesn't already exist.
You don't want people creating new stores, with new IDs, just by misspelling a store's name slightly.
Adding to a Multi-Key field
You can check to see that the ID is not already there before adding. = This saves disk space if there are going to be a lot of duplicates, but functionally it doesn't make any difference in a key field; FileMaker ignores duplicates in any indexed value list, and still matches the same records. You can also use PatternCount, then some other text functions (Middle, Position) to strip an ID out of the field, too. I'll have to leave that as a reader exercise for now.
Key fields
Backwards, from Store to Events
You could easily make a similar relationship back to the Peoples file, if you just wanted to go straight to the people and ignore all the events.
This would show just one entry for a person, rather than possibly several in the Events file.
Events Portal in People
Portal Disclaimer In the example files, the "line item" records are being created directly in the join file, so there was little need to have record creation in portals. And, as I said, the filtered list complicated creating records in the portal. I tend to write about what I find interesting and useful, which means I may get ahead of myself from time to time. It is difficult to cover a program like FileMaker in a monthly column without wandering a bit. You can always send me an email and tell me where I lost you.
Portability of the Multi-Key field There was a little more maintenance. Every time a new "event" was created for a person, the multi-key field from that person's previous event record had to be inserted into the new record.
For that matter, you could put a multi-key field in Peoples, so that you had one in Storess, with the People IDs, and another in Peoples, with the Store IDs.
Letters What if you wanted to send the same letter to several people--not everyone--but a selected group. In this case you might want to keep track of who got the letter. But it wouldn't really work to create a new record in the letter file for each recipient. One solution is to store the IDs of those contacts in a multi-key field in the letter file. You would only do this for the "mass" mailings; with a normal letter the Contact ID would just go in a regular Contact ID field in Letters. A relationship from this Contact IDs multi-key back to the contacts file could immediately isolate all those who got that particular mass mailing. You would only need one record in Letters for the letter itself.
The way that you would get the contact IDs would be to use the before mentioned Copy All Records. You'd Copy all those IDs from the found set in Contacts, then Paste them into the Mass-mailing Contact IDs field for that letter in Letters.
Passwords This may confuse those who try the example files without reading this article :-)
Version 5 and Related Value Lists I don't know all the uses of this, but one thing it would do is allow you to use the built-in value list mechanism to pop up a filtered list. In other words, rather than have the filtered stores show in a little window, they could pop up (or down actually) directly from the field itself. This would make a cleaner interface; and it would also work within a portal. By setting a filtering value into a global field first, then going to the field to drop down the list, you could dynamically filter a list in different ways, from any of your files, much like you can filter portals now. Neato.
Namess?
Fenton Jones
Websites mentioned:
FileMaker 101 - Previous Columns
|
|
Copyright ©1995-2000 My Mac Productions, All Rights Reserved |