Set Field By Name
Purpose 
Replaces the entire contents of a calculated target field in the current record with the result of the calculated value.
Format 
Set Field By Name[<calculated target field>; <calculated value>]
Options 
 •
Select Specify target field or click Specify to create a calculation to specify the field whose contents you want to replace. In the Specify Calculation dialog box, use the field list (on the left) and the functions list (on the right) with the mathematical and text operators to build the calculation.
 •
For Calculated result, click Specify to define the calculated value.
Compatibility 
 
Where the script step runs 
Supported 
FileMaker Pro 
Yes 
FileMaker Server scheduled script 
Yes 
FileMaker Go 
Yes 
Custom Web Publishing 
Yes 
Instant Web Publishing 
Yes 
Runtime solution 
Yes 
Originated in 
FileMaker Pro 10.0
Description 
The Set Field By Name script step lets you create a calculation to specify a field name, then change the value of the field either literally or based on a second calculation.
The calculated target field must return a text result.
If quotation marks are not included around the fully qualified field name, the target field name is obtained from the named field.
If no field is specified and a field is selected in Browse mode or Find mode, that field is used.
Notes
 •
 •
 •
When possible, the Set Field By Name script step makes the record active and leaves it active until the record is exited or committed. Scripts that use a series of Set Field By Name script steps should group these steps together if possible, so that subsequent Set Field By Name script steps can act on the record without having to lock the record, download and upload data, index the field, and so on, after each individual Set Field By Name script step. These functions and record-level validation are performed after the record has been exited or committed.
Example 1
In the following example, a calculation identifies the target field in which a value should be replaced based on the geographical location in which the data was entered. Then the script enters a calculated value in the target field based on the appropriate currency exchange rate.
Set Field By Name
[If (Members::Country = "USA" ;
"Members::Fee Paid-USD" ; "Members::Fee Paid-GBP");
If (Members::Country = "USA" ;
Members::Fee*<USCurrencyRate> ;Members::Fee*<GBCurrencyRate>)];
Example 2
The following example replaces the contents of the Country field located in Table1 with the data located in the Name field in related Table2.
Set Field By Name["Table1::Country";Table2::Name]
Note  To ensure proper evaluation, FileMaker Pro must treat the target field as a literal string. Therefore, you must include quotation marks around the calculated target field.
Example 3
The following example replaces the contents of the global target field with the data value located in the Name field in related Table2.
In this example, Table1::FullName contains the literal value “Table1::FullName” and Table2::Name contains “John Smith”. After the step completes, the value in “Table1::FullName” is “John Smith”.
Set Field By Name[“Table1::FullName”;Table2::Name]
Note  The context for the calculation (determined in the upper left corner of the Specify Calculation dialog box) is essential for proper evaluation.
Example 4
The following example uses the GetFieldName function to ensure that FileMaker Pro retrieves the fully qualified name of the target field and the Evaluate function to extract the value stored in the target field, then replaces the contents of fieldName with the data value located in the Name field in related Table2.
Set Field By Name
[GetFieldName(Evaluate(Location::fieldName));Table2::Name]
Example 5
This example uses a field name contained in a variable to calculate temperatures. A user enters the temperature in field F or field C and runs the script in order to convert temperatures between Fahrenheit and Celsius.
If [Get (ActiveFieldName) = “F”]
#Convert Fahrenheit to Celsius
Set Variable [$TargetField; Value:”TableName::C”]
Set Field By Name [$TargetField; (5/9)*(Get (ActiveFieldContents)-32)]
Else if [Get (ActiveFieldName) = “C”
#Convert Celsius to Fahrenheit
Set Variable [$TargetField; Value:”TableName::F”]
Set Field By Name [$TargetField; (9/5)*Get (ActiveFieldContents)+32]
Related topics 
Script steps reference (alphabetical list)
Script steps reference (category list)