首页 > 解决方案 > 如何编写适用于任何表的通用 Filemaker 搜索/脚本?

问题描述

我正在尝试在 Filemaker 19 中创建一个可重复用于许多表的脚本,并发现所有搜索的函数总是需要我指定表,并且我不能使用计算出的表名。

我想要一个简单的“仅显示新记录”功能。我所有的表都有一个相同的“创建于”字段。我不想写很多其他相同的脚本。

有没有办法说“将此搜索应用于当前表”或“应用于名为 $table 的表”或类似的东西?

标签: filemaker

解决方案


如果所有表中的字段名称都相同(例如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 )是避免在脚本中硬编码表/字段名称的好方法,这将保护您的脚本免受表/字段名称更改的影响。但是默认字段名称硬编码的,因此如果您使用这种通用查找方法,请注意在管理 > 数据库中更改它。


推荐阅读