Replace Field Contents by Name
Replaces the value in a calculated target field in every record in the found set with a different value.
Options
-
With dialog specifies whether to display the Replace Field Contents dialog box when the script step is performed.
-
Specify target field specifies a calculation that returns the name of the target field as text. The result must be a fully qualified field name, in the form
Table::Field. -
Replace with "current contents" uses the current value in the target field as the replacement value to place in that field in every other record in the current found set.
-
Replace with serial numbers reserializes the field in every record in the current found set.
-
Entry options uses the next available value in Entry Options as the first record number, incrementing with whatever value is in Entry Options.
-
Custom Values lets you enter a value to be used as a starting point for the serialization, as well as a value by which to increment each serialized field in the current found set.
-
Update serial number in Entry Options? resets the serial number value in Entry Options so that the next serial number that is automatically entered will follow the records you have reserialized with this script step. If this option is not used, the serial value in Entry Options is not changed, and may not be in sequence with the newly reserialized records.
If the field to be replaced was set up for auto-entry of a serial number and Prohibit modification of value during data entry is not selected, FileMaker Pro will still put sequential numbers in the selected field, but will do so starting with the next number to be automatically entered.
-
-
Replace with calculated result displays the Specify Calculation dialog box, where you can enter a calculation to be used as the replacement value.
-
Perform auto-enter options for fields controls whether other fields with auto-enter options are updated as this script step updates records.
Compatibility
| Product | Supported |
| FileMaker Pro | Yes |
| FileMaker Go | Partial |
| FileMaker WebDirect | Partial |
| FileMaker Server | Partial |
| FileMaker Cloud | Partial |
| FileMaker Data API | Partial |
| Custom Web Publishing | Partial |
Originated in version
26.1
Description
This script step works like the Replace Field Contents script step, except that the target field name is the result of a calculation. Use this script step when the target field isn't known until the script runs. For example, when the target field name is calculated from a variable used as a counter in a loop, from record data, or from JSON data returned by a REST API call.
Important Replace Field Contents by Name modifies all records in the found set. You cannot undo a Replace Field Contents by Name script step.
Notes
-
If the result of Specify target field names a table that doesn't exist, this script step returns error code 106 ("Table is missing"). If the field doesn't exist, or the result doesn't include a table name, this script step returns error code 102 ("Field is missing").
-
For more notes, see Replace Field Contents script step.
Example 1
Sets the Category field to Uncategorized in all records in the found set. The target field name is built from the table name of the current layout, so the script works on any layout whose table has a Category field.
Perform Find [ Restore ]
Replace Field Contents by Name [ With dialog: Off ; Target: Get ( LayoutTableName ) & "::Category" ; Calculated result: "Uncategorized" ]
Example 2
Removes the placeholder text "N/A" from all fields on the current layout that are accessible to a find, in all records in the found set.
Show All Records
Set Variable [ $fields ; Value: JSONListKeys ( GetFieldsOnLayout ( Get ( LayoutName ) ) ; "fields" ) ]
Set Variable [ $i ; Value: 1 ]
Loop [ Flush: Always ]
Exit Loop If [ $i > ValueCount ( $fields ) ]
Set Variable [ $field ; Value: GetValue ( $fields ; $i ) ]
Replace Field Contents by Name [ With dialog: Off ; Target: $field ; Calculated result: If ( GetField ( $field ) = "N/A" ; "" ; GetField ( $field ) ) ]
Set Variable [ $i ; Value: $i + 1 ]
End Loop
Example 3
Removes leading and trailing spaces from each field in a list of fields, in all records in the found set. The script collects the error code for each field that fails, then shows the results.
Set Error Capture [ On ]
Go to Layout [ "Products" ]
Show All Records
Set Variable [ $fields ; Value: List ( "Products::ProductName" ; "Products::Category" ; "Products::Caption" ) ]
Set Variable [ $i ; Value: 1 ]
Set Variable [ $errors ; Value: "" ]
Loop [ Flush: Always ]
Exit Loop If [ $i > ValueCount ( $fields ) ]
Set Variable [ $field ; Value: GetValue ( $fields ; $i ) ]
Replace Field Contents by Name [ With dialog: Off ; Target: $field ; Calculated result: Trim ( GetField ( $field ) ) ]
Set Variable [ $error ; Value: Get ( LastError ) ]
If [ $error ≠ 0 ]
Set Variable [ $errors ; Value: List ( $errors ; $field & ": error code " & $error ) ]
End If
Set Variable [ $i ; Value: $i + 1 ]
End Loop
If [ not IsEmpty ( $errors ) ]
Show Custom Dialog [ "Some fields were not updated" ; $errors ]
End If