Defining value lists using calculations
A calculated value list generates its items from a calculation. For example, a calculation can return different items depending on the value of a variable. The items can change whenever FileMaker clients reevaluate the calculation, such as when the window is refreshed.
To define a value list using a calculation:
-
Choose File > Manage > Value Lists.
-
In the Manage Value Lists dialog, click New.
-
In the Edit Value List dialog, for Value List Name, type a name.
-
Select Use calculated value list.
The Specify Calculation dialog opens. To change the calculation later, click Specify.
-
Enter an expression that returns one of the following:
-
A return-delimited list of values for a single-column value list
-
A JSON object for different display and entry values, or for a two-column value list
-
-
Click OK twice.
-
Format a field to display values from the value list.
See Setting up a field to display a pop-up menu, checkbox set, or other control.
Using a return-delimited list for single-column value lists
Each line in the calculation result is one value in the value list (a trailing return is ignored).
For example:
List ( "Red" ; "Green" ; "Blue" )
This creates a value list with three values.
The expression can also be or include a variable that contains a return-delimited list, so you can change the value list with a script. For example, use the Set Variable script step to set $$colors, then specify $$colors as the expression.
Using JSON for display and entry values, or two-column value lists
Use JSON to display one value and enter another, or to display two values. The JSON must have this structure:
{
"ValueList" : {
"values" : [
{ "display" : "First Item" },
{ "display" : "Second Item" }
]
}
}
The values array lists the items in the order they appear in the value list. Each element is an object that must include the display key and can include one second key:
|
Second key |
Value list shows |
Field stores |
|
None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Use the same second key in every element. If elements use different second keys, the second key in the last element that has one determines how the whole value list displays and enters values.
For example, this expression returns JSON in which each element has a display key and an enterSecond key:
JSONSetElement ( "{}" ;
[ "ValueList.values[+].display" ; "Small" ; JSONString ] ;
[ "ValueList.values[:].enterSecond" ; "S" ; JSONString ] ;
[ "ValueList.values[+].display" ; "Medium" ; JSONString ] ;
[ "ValueList.values[:].enterSecond" ; "M" ; JSONString ] ;
[ "ValueList.values[+].display" ; "Large" ; JSONString ] ;
[ "ValueList.values[:].enterSecond" ; "L" ; JSONString ]
)
It returns this JSON:
{
"ValueList" : {
"values" : [
{ "display" : "Small", "enterSecond" : "S" },
{ "display" : "Medium", "enterSecond" : "M" },
{ "display" : "Large", "enterSecond" : "L" }
]
}
}
When a field object uses this value list, it shows Small, Medium, and Large. When you choose Medium, the field stores M.