Search code examples
filemaker

Filemaker: Best way to set a certain field in every related record


I have a FileMaker script which calculates a value. I have 1 record from table A from which a relation points to n records of table B. What is the best way to set B::Field to this value for each of these n related records?

Doing Set Field [B::Field; $Value] will only set the value of the first of the n related records. What works however is the following:

Go to Related Record [Show only related records; From table: "B"; Using layout: "B_layout" (B)]
Loop
    Set Field [B::Field; $Value]
    Go To Record/Request/Page [Next; Exit after last]
End Loop
Go to Layout [original layout]

Is there a better way to accomplish this? I dislike the fact that in order to set some value (model) programmatically (controller), I have to create a layout (view) and switch to it, even though the user is not supposed to notice anything like a changing view.


Solution

  • FileMaker always was primarily an end-user tool, so all its scripts are more like macros that repeat user actions. It nowhere near as flexible as programmer-oriented environments. To go to another layout is, actually, a standard method to manipulate related values. You would have to do this anyway if you, say, want to duplicate a related record or print a report.

    So:

    1. Your script is quite good, except that you can use the Replace Field Contents script step. Also add Freeze Window script step in the beginning; it will prevent the screen from updating.

    2. If you have a portal to the related table, you may loop over portal rows.

    3. FileMaker plug-in API can execute SQL and there are some plug-ins that expose this functionality. So if you really want, this is also an option.

    I myself would prefer the first variant.