Filemaker:在每个相关记录中设置特定字段的最佳方式
我有一个计算值的 FileMaker 脚本。我有表 A
中的 1 条记录,其中的关系指向表 B
的 n 条记录。对于这些 n 条相关记录,将 B::Field
设置为此值的最佳方法是什么?
执行 Set Field [B::Field; $Value]
只会设置 n 条相关记录中第一个的值。然而,有效的方法如下:
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]
是否有更好的方法来实现这一目标?我不喜欢这样的事实:为了以编程方式(控制器)设置某些值(模型),我必须创建一个布局(视图)并切换到它,即使用户不应该注意到任何诸如更改视图之类的事情。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FileMaker 始终主要是一个最终用户工具,因此它的所有脚本更像是重复用户操作的宏。它远不如面向程序员的环境那么灵活。转到另一个布局实际上是操作相关值的标准方法。如果您想要复制相关记录或打印报告,无论如何您都必须执行此操作。
因此:
您的脚本非常好,只是您可以使用“替换字段内容”脚本步骤。还在开头添加冻结窗口脚本步骤;它会阻止屏幕更新。
如果您有相关表的入口,您可以循环入口行。
FileMaker 插件 API 可以执行 SQL,并且有一些插件可以公开此功能。因此,如果您确实想要,这也是一个选择。
我本人更喜欢第一个变体。
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:
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.
If you have a portal to the related table, you may loop over portal rows.
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.
循环访问相关记录的门户
循环访问具有相关记录的门户并设置字段比替换或转到记录、设置字段循环有几个优点。
您不必离开布局。如果布局上尚未存在门户,则可以将其隐藏或放置在屏幕外。
您可以通过事务方式完成此操作。 IE 中,您可以确保所有记录都得到编辑,或者没有任何记录得到编辑。这很重要,因为在多用户网络解决方案中,记录可能并不总是可编辑的。如果没有门户,替换或循环记录都不是事务安全的。
以下是有关 FileMaker 事务的一些信息。
您可以使用“转到门户行”循环浏览门户。就像这样:
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.
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.
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:
这取决于您使用该值的目的。如果您需要硬连接某个字段,那么听起来您没有一个非常规范化的数据结构。最简单的方法是在 TableB 中进行计算而不是存储字段,或者如果这是存储的内容,它是否可以是查找字段而不是在记录创建时设置?
TableB 中的字段有何用途以及如何使用?
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?