filemaker - 如何编写适用于任何表的通用 Filemaker 搜索/脚本?
问题描述
我正在尝试在 Filemaker 19 中创建一个可重复用于许多表的脚本,并发现所有搜索的函数总是需要我指定表,并且我不能使用计算出的表名。
我想要一个简单的“仅显示新记录”功能。我所有的表都有一个相同的“创建于”字段。我不想写很多其他相同的脚本。
有没有办法说“将此搜索应用于当前表”或“应用于名为 $table 的表”或类似的东西?
解决方案
如果所有表中的字段名称都相同(例如TableName::dateField
,这样的脚本可以工作:
Enter Find Mode [ Pause: OFF ]
Set Field By Name [ Get ( LayoutTableName ) & "::dateField" ; Value: ">=" & Get ( CurrentDate ) ]
Perform Find
如果字段名称不同,您可能需要添加一些额外的分支逻辑。例如这样的:
If [ Get ( LayoutTableName ) = GetValue ( Substitute ( GetFieldName ( Contacts::creationDate ) ; "::" ; ¶ ) ; 1 ) ]
Set Variable [ $fieldName ; GetFieldName ( Contacts::creationDate ) ]
Else If [ Get ( LayoutTableName ) = GetValue ( Substitute ( GetFieldName ( Invoices::invDate ) ; "::" ; ¶ ) ; 1 ) ]
Set Variable [ $fieldName ; GetFieldName ( Invoices::creationDate ) ]
# Add more Else If blocks as needed...
Else
Set Variable [ $fieldName ; Get ( LayoutTableName ) & "::defaultDateField" ]
End If
Enter Find Mode [ Pause: OFF ]
Set Field By Name [ $fieldName ; Value: ">=" & Get ( CurrentDate ) ]
Perform Find
上面喜欢的部分GetValue ( Substitute ( GetFieldName ( Invoices::invDate ) ; "::" ; ¶ ) ; 1 )
是避免在脚本中硬编码表/字段名称的好方法,这将保护您的脚本免受表/字段名称更改的影响。但是默认字段名称是硬编码的,因此如果您使用这种通用查找方法,请注意在管理 > 数据库中更改它。
推荐阅读
- regex - 从文本文件中删除行号
- excel - 同时更改循环VBA的变量
- file - Netlogo 文件打开错误“预期 nlogo 文件有 12 个部分,这有 1 个”
- apache-kafka - 以最小延迟向 Kafka 添加元素的快速协议?
- ios - UICollectionView 自定义布局单元格类型相关属性
- java - 骰子 JAVAFX 的最后一个值
- android - 应用程序快捷方式:minSdk<25 的 Lint 警告
- scala - 带有 Ordering 和 ClassTag 的 scala 多态类型签名
- java - java - list.add 覆盖以前的对象
- css - css 表:具有交替行颜色的固定列?