Set Field By Name
•
|
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.
|
Where the script step runs
|
|
|
|
FileMaker Server scheduled script
|
|
|
|
|
|
|
|
|
|
•
|
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.
|
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>)];
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”.
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.
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]