
Function: FileMaker Calculations
The core idea behind creating the ACF language is to seamlessly integrate FileMaker calculations into the language. This integration includes the following aspects:
- Access to FileMaker Variables
- Access to Field content in the current relationship graph
- Explicit handling of calculations by passing them over to the FileMaker Calculation engine to call custom functions or other types of calculations.
- Setting values to FileMaker variables.
- Note: Directly setting field content is not possible, but it can be achieved using SQL functions.
Examples:
// Get value from a FileMaker variable:
string fileName = $$FileName;
// Set a value back to a FileMaker variable:
$$FileName = fileName;
// Get Value from a field:
string rootPath = preferences::docRootPath;
// Get value from a field by constructing the table occurrence:
string PreferencesTable = "Orders_preferences";
rootPath = eval(PreferencesTable + "::docRootPath");
// Perform a FileMaker Calculation
string tempfolder = @Get(TemporaryPath)@;
// Alternatively, we have our own function.
tempfolder = temporary_directory(); // tempfolder already declared above....
// Performing a multi-line FileMaker calculation; if the calculation contains the @-sign,
// one must use this for One-liners as well.
string SQLresult = @@ExecuteSQL ( "Select blabla.....
WHERE blabla....
ORDER BY bla bla...."; "||"; "|*|")@@;
// Or - we could simply use the plugin's SQL-function directly without using the FM-engine:
string SQLresult = ExecuteSQL ( "Select blabla.....
WHERE blabla....
ORDER BY bla bla....", "||", "|*|");
// If you need to construct the calculation, you must use the "eval" function.
// as the @-notation expects a constant string.
int day = 14, month = 11, year = 2018;
string result = eval ( "Date(" + month + ";" + day + ";" + year + ")");
// or easier using the format function.
result = eval ( format ( "Date(%d;%d;%d)", month, day, year) ) ;
When working with FileMaker calculations, it's advisable to use the data viewer to construct the calculation. You can then paste it into your ACF code. This allows you to test and verify the expected results before integrating it into your code.
Regarding the @-notation or @@-notation, the content between the @ symbols is treated as a string literal and evaluated as a calculation by FileMaker when used in ACF functions. You cannot manipulate the content at runtime as it is executed immediately. To construct something for evaluation or include parameters, you can use the eval
function, which evaluates a string expression.
One method to deal with variable content in these notations is to set FileMaker variables with the content you want and then use those variables in the calculation.
Error Handling:
FileMaker evaluations sometimes return a "?" if something goes wrong. In such cases, ACF will throw a runtime exception, aborting the function call, and returning a proper error message. This message includes the function it attempted to execute in plain text. These errors can sometimes be easy to overlook in regular scripting until you notice that something isn't working. It's essential to catch and handle these errors appropriately in your code.
Example:
ERROR: The FileMaker Evaluation returned an error (?) for the expression: Date ( 2018; 12; 9)
This section provides guidance on integrating FileMaker calculations seamlessly into your ACF code, highlighting important considerations and error handling practices.