开发者

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开发者_如何学Go 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.


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.


Loop through a Portal of Related Records

Looping through a portal that has the related records and setting the field has a couple of advantages over either Replace or Go To Record, Set Field Loop.

  1. You don't have to leave the layout. The portal can be hidden or place off screen if it isn't already on the layout.

  2. You can do it transactionally. IE you can make sure that either all the records get edited or none of them do. This is important since in a multi-user networked solution, records may not always be editable. Neither replace or looping through the records without a portal is transaction safe.

Here is some info on FileMaker transactions.

You can loop through a portal using Go To Portal Row. Like so:

Go To Portal Row [First]
Loop
    Set Field [B::Field; $Value]
    Go To Portal Row [Next; Exit after last]
End Loop


It depends on what you're using the value for. If you need to hard wire a certain field, then it doesn't sound like you've got a very normalised data structure. The simplest way would be a calculation in TableB instead of a stored field, or if this is something that is stored, could it be a lookup field instead that is set on record creation?

What is the field in TableB being used for and how?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜