如何编写适用于任何表的通用 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 ) 这样的部分是避免在脚本中硬编码表/字段名称的好方法,这将保护您的脚本免受表/字段名称更改的影响。但是默认字段名称​​是硬编码的,因此如果您使用这种通用查找方法,请注意在“管理”>“数据库”中更改该名称。