| Class | Rfm::Layout |
| In: |
lib/rfm_command.rb
|
| Parent: | Object |
The Layout object represents a single FileMaker Pro layout. You use it to interact with records in FileMaker. All access to FileMaker data is done through a layout, and this layout determins which table you actually hit (since every layout is explicitly associated with a particular table — see FileMakers Layout->Layout Setup dialog box). You never specify table information directly in RFM.
Also, the layout determines which fields will be returned. If a layout contains only three fields from a large table, only those three fields are returned. If a layout includes related fields from another table, they are returned as well. And if the layout includes portals, all data in the portals is returned (see Record::portal for details).
As such, you can significantly improve performance by limiting what you put on the layout.
The Layout object is where you get most of your work done. It includes methods for all FileMaker actions:
In FileMaker, execution of a script must accompany another action. For example, to run a script called _Remove Duplicates_ with a found set that includes everybody named Bill, do this:
myLayout.find({"First Name" => "Bill"}, :post_script => "Remove Duplicates")
When you perform an action in FileMaker, it always executes in this order:
You can control when in the process the script runs. Each of these options is available:
If you want to pass a parameter to the script, use the options above, but supply an array value instead of a single string. For example:
myLayout.find({"First Name" => "Bill"}, :post_script => ["Remove Duplicates", 10])
This sample runs the script called "Remove Duplicates" and passes it the value +10+ as its script parameter.
Most of the methods on the Layout object accept an optional hash of options to manipulate the action. For example, when you perform a find, you will typiclaly get back all matching records. If you want to limit the number of records returned, you can do this:
myLayout.find({"First Name" => "Bill"}, :max_records => 100)
The +:max_records+ option tells FileMaker to limit the number of records returned.
This is the complete list of available options:
The Layout object has a few useful attributes:
Note: It is possible to put the same field on a layout more than once. When this is the case, the value in field_controls for that field is an array with one element representing each instance of the field.
| db | [R] | |
| name | [R] |
Initialize a layout object. You never really need to do this. Instead, just do this:
myServer = Rfm::Server.new(...) myDatabase = myServer["Customers"] myLayout = myDatabase["Details"]
This sample code gets a layout object representing the Details layout in the Customers database on the FileMaker server.
In case it isn’t obvious, this is more easily expressed this way:
myServer = Rfm::Server.new(...) myLayout = myServer["Customers"]["Details"]
Creates a new record in the table associated with this layout. Pass field data as a hash in the values parameter. Returns the newly created record in a RecordSet. You can use the returned record to, ie, discover the values in auto-enter fields (like serial numbers).
For example:
result = myLayout.create({"First Name" => "Jerry", "Last Name" => "Robin"})
id = result[0]["ID"]
The above code adds a new record with first name Jerry and last name Robin. It then puts the value from the ID field (a serial number) into a ruby variable called id.
Deletes the record with the specified internal recid. Returns a ResultSet with the deleted record.
For example:
recid = myLayout.find({"First Name" => "Bill"})[0].record_id
myLayout.delete(recid)
The above code finds every record with Bill in the First Name field, then deletes the first one.
Updates the contents of the record whose internal recid is specified. Send in a hash of new data in the values parameter. Returns a RecordSet containing the modified record. For example:
recid = myLayout.find({"First Name" => "Bill"})[0].record_id
myLayout.edit(recid, {"First Name" => "Steve"})
The above code would find the first record with Bill in the First Name field and change the first name to Steve.
Finds a record. Typically you will pass in a hash of field names and values. For example:
myLayout.find({"First Name" => "Bill"})
Values in the hash work just like value in FileMaker’s Find mode. You can use any special symbols (+==+, +…+, +>+, etc…).
If you pass anything other than a hash as the first parameter, it is converted to a string and assumed to be FileMaker’s internal id for a record (the recid).