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:

  1. Choose File > Manage > Value Lists.

  2. In the Manage Value Lists dialog, click New.

  3. In the Edit Value List dialog, for Value List Name, type a name.

  4. Select Use calculated value list.

    The Specify Calculation dialog opens. To change the calculation later, click Specify.

  5. 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

    See Specify Calculation dialog box.

  6. Click OK twice.

  7. 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:

Copy
{
  "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

display value

display value

displaySecond

display and displaySecond values

display value

enterSecond

display value

enterSecond value

displayAndEnterSecond

display and displayAndEnterSecond values

displayAndEnterSecond value

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:

Copy
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:

Copy
{
  "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.