Reference > Script steps reference > Fields script steps > Set Field By Name
 
Set Field By Name
Purpose 
Replaces the entire contents of a calculated target field in the current record with the calculated value.
See also 
Format 
Set Field by Name[<calculated target field>; <formula>]
Options 
Specify target field is a calculation to specify the field whose contents you want to replace.
Calculated result specifies the calculation whose results will be inserted by this script step.
Compatibility 
 
Where the script step runs 
Supported 
FileMaker Pro 
Yes 
FileMaker Server 
Yes 
FileMaker Go 
Yes 
Custom Web Publishing 
Yes 
FileMaker WebDirect 
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.
Because the target field is calculated, a single Set Field By Name step can replace multiple Set Field script steps between If conditions.
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 
The specified target field doesn’t have to be on the current layout.
Set Field By Name ignores validation checking.
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 
Identifies the target field (National Statistics or World Statistics) based on geographical location, then enters a calculated value (the sum of all Grand Totals) in the target field.
Set Field by Name [If ( Customers::Country = "Japan" ; "Customers::National Statistics" ; "Customers::World Statistics" ); Sum ( Invoices::Grand Total )]
Example 2 
Demonstrates when to use Set Field By Name instead of Set Field to simplify scripts.
#With Set Field, an If statement with multiple Else If steps is needed
#to determine which field on the Customers table to update
#with information from Credit Collection::Phone Number.
If [Credit Collection::Call Location = "Work"]
Set Field [Customers::Work Phone; Credit Collection::Phone Number]
Else If [Credit Collection::Call Location = "Home" ]
Set Field [Customers::Home Phone; Credit Collection::Phone Number]
Else If [Credit Collection::Call Location = "Mobile" ]
Set Field [Customers::Mobile Phone; Credit Collection::Phone Number]
End If
#A single Set Field by Name script step can perform the same task
#by using a calculation to determine the target field.
Set Field by Name [GetFieldName ( Evaluate ( Credit Collection::Call Location & " Phone" ) ); Credit Collection::Phone Number]
Related topics 
Script steps reference (alphabetical list)
Script steps reference (category list)