The A-Z of FileMaker: M is for Merge

There are a number of methods to display data on a FileMaker layout, the most common being using field objects. Often it is more convenient and flexible to use merge items within a text object.

What can be merged in text?

Text objects can contain three types of merge data:

  • fields
  • variables
  • symbols

All can be accessed via the Insert menu while working in Layout mode.

Insert menu merge

What do merge items look like?

When looking at a text object in Layout mode, merge fields and variables in the text appear within double chevrons <<like this>> and <<$likethis>>; merge symbols are enclosed in double curly braces {{like this}}.

merge items in layout mode

Merge fields

When inserting merge fields, you can specify any field that you could physically place on the layout (current table, related or global). Text objects containing merge fields can be placed as you would normal fields – on the layout, in a portal, in a popover, etc – and will display the same data as it would for a standard field object.

The exception for using merge fields is container fields. If these are merged, the text object will display the container data file name.

Concatenating data

Merge fields can be very useful for stringing together (concatenating) data. A common example is when displaying a person’s full name – you will want a single space between first and last names or perhaps a comma and space between last and first names. This can be done using a calculation field but merge fields for display may save creating a number of calculations.

concatenate with merge

Note also in the above that the merge fields have been formatted with styling (bold and uppercase) within the text object.

Merge variables

You can insert both local ($) and global ($$) variables in text objects. The value of a local variable will only be displayed during the script in which it exists.

To ensure correct display, you will need to use either the Refresh Window or Refresh Object (specifying the named text object) script step.

Tip: Displaying page count

As in the above screenshot, you may want to display the page count in the footer of a report – Page 3 of 10. While the page number is displayed with a symbol, the page count is determined dynamically for the report. When in Preview mode, you will go to the last page using the Go to Record/Request/Page [Last] script step, and set a variable to Get ( PageNumber ).

Idea: use Merge variables as Layout calculations

There have been various feature requests over the years for layout calculations. This feature would reduce the need for calculation fields in tables. Merge variables may satisfy that request in a number of cases. During a script, you can define a variable using any calculation. Then you can display the result of the calculation on a layout using a merge variable.

Merge symbols

Merge symbols use the Get functions available in the calculation engine (see the blog article The A-Z of FileMaker: G is for Get for more). If the function used is Get (AccountName), then the merge symbol is {{AccountName}}.

The merge symbol displays the result of the Get function in Browse, Find and Preview modes. It is evaluated when the text object is drawn on the layout and when it is refreshed.

Challenge

If the {{CurrentTime}} merge symbol is placed on a tab panel that is not the default front tab, when will the current time be evaluated?

a. when the layout first loads
b. when the tab panel is first selected
c. every time the tab panel is selected
d. when any tab panel is selected

(answer is at the end of the article but you would be wise to experiment for yourself to see whether your results agree)

The most commonly used merge symbols are available for immediate selection – date, time, user name, page number and record number. All others can be accessed through the Other Symbol… command and dialog.

Formatting merge data

Data displayed by merge fields, variables and symbols can be formatted for display by applying Data Formatting via the Inspector to the text object.

Only one format per data type (number, date, time) can be applied to a single text object. This means that it is not possible to have two numbers in a single text object display with different formatting.

CHALLENGe Answer

b. when the tab panel is first selected

After that event, it will not be re-evaluated except if the window or object is refreshed. If the window is refreshed and the tab panel is not active, then it behaves as it does when the layout is first loaded – it evaluates next time the tab panel is selected.

Why is this useful to know? It contributes to an understanding of how FileMaker draws layouts and layout objects, and when it evaluates calculations. Such understanding will help a developer to create efficient layouts and troubleshoot performance.