|
|
|
Navigate: | My Mac Online | The Archives | June 2000 | FileMaker 101 - Part 27 | |
![]() |
|
![]() Part 27
My Mac Magazine manavesh@mymac.com
Walking the Relationships [How to use relationships to move between and perform operations on different sets of records during scripts.] I don't know what others call this, but it is a fairly common task in any kind of scripting. I think they call it "walking the lists" in AppleScript. By "walking the relationships" I mean using the power of relationships (often self-relationships) to move between defined groups of records during a script. Each group can then be operated on independently, while preserving not only the current found set, but returning to the same record. As far as the user is concerned, all (s)he did was click a checkbox or something; several operations occurred, but the screen just blinked for a second. A situation where this is needed is when something happens to one record, but the change then requires running an operation on several records, a set that is different from the current found records. It's hard to come up with specific examples. It generally occurs when you have some complexity, records tied together with self-relationships; then have another element added (or deleted) later by the user. This element is often "arbitrary," simply up to user discretion as to when and to which records it happens. What needs to happen is for the change that has been made to be applied to all the related records. But, in this case, they aren't part of the found set. If you Go To Related Records and Replace the change into the related records, you'll lose the found set. Two simple examples of this kind of change that come to mind are, 1. a simple checkbox, and 2. user deletion or editing of the first marked record of a set. I'll cover the first problem in this article.
Split Transactions I went to some trouble to create the ability for "split transactions." An entry, which is normally one transaction to one store, can be split, each partial amount assigned to different people (or jobs), while still remaining available as the single transaction.
The way I did this was to actually create a new record for each person added to the split, tying them together with a self-relationship using the value of the first record's Serial ID field.
Any subsequent split entries would use this same Split ID. A self-relationship on the Split ID ties the transaction records together. The transaction total is the Sum of the related entry amounts, = In my file, I am not that interested in the transaction total, after it is entered. I am usually viewing the entries by client (or job*), and I am mostly concerned with how much each job is costing. The entries for that job, whole or split, show on the list view, and are totalled at the bottom of the screen. The transaction total is only viewed in a "drop-down" view when clicking the Splits button. It's kind of the opposite of the way checkbook registers usually show this; but it makes more sense in structural terms for what I'm doing. Each split entry is a record of its own, can be assigned to a job separately, and shows up in summaries etc..
*In my own file I have Clients and Jobs; but it added extra fields, so in the examples I just have it by Client. You could easily change it to Jobs. You'd get the client's name through a Jobs file, reaching back to a Clients file.
Not a Ledger-type Structure
In that case, you'd need the total of the splits, the transaction, to be an indexed number, not a Sum(Relationship::number). It would need a slight re-write, mostly in the Set Remainder script. It would need a different layout to show the transaction total, not the amount for each client. But it's also off the subject, which I haven't really got to yet :-)
Check Off
Returning to the Same Place
First we set the Serial ID into a global Serial ID g field, for temporary storage.
Also create a relationship, named "Serial ID g," Serial ID g = ::Serial ID.
Now we just need 1 step to return to the current record:
Check It On or Off?
Check Button Set Field ["CheckOff", "If (CheckOff, "", 1)"] [Notice that since Checkoff is a number (in fact can only be 1 or nothing, is Boolean) just seeing if it exists is enough. Don't try this on text fields; use IsEmpty(field) instead.] We now need to check off the other split entries for that transaction as well. This would be done with a Replace step, after isolating those records. Remember that the field to be Replaced must be on the current layout (in this case it is, but always check). The script will need to know whether it's "on" or "off" as we run the Replace, so let's put that value into a global, CheckOff g, where it will be accessible.
Set Field ["CheckOff g","CheckOff"]
Check Off Script
Enter Browse Mode [] Notice that the first Go To Related Record step has "Show," while the last doesn't; also that the last is after the Sort step (which always ends up on the 1st record). I put "Find All" so you end up with all of them and can see what's happening. In my own files I have it end up with the current Job's records. All records would be a bit much. Without either of these steps you would end up with just the records on the current split. Take it out and see. It won't hurt anything.
Check Off Many Records
Splits1 vs. Splits2 Also notice the difference in the data in the Last Name fields between the two Split files (go to the Calc layout in each file). I can't really go into detail about how and why I set up the lookup, and why there is only data in the first entry for each Client, other than that it is the most efficient way to store the transaction data without using a lot of disk space. The client's name would also be in a Contacts-type file.
The Client ID field carries all the weight. It is in every record. With it you can access the names and keep everything properly linked. A self-relationship on it allows you to store the names only once, but still see them in every line of the list.
Fenton Jones
Websites mentioned:
FileMaker 101 - Previous Columns
|
|
Copyright ©1995-2000 My Mac Productions, All Rights Reserved |