Inserting merge variables onto a layout
You can create a merge variable that displays a value from a variable. You can use merge variables for some tasks in place of global fields or unstored calculation fields. For example, a merge variable could display the total cost at the bottom of an invoice, or display the name of the account used to print a report.
You see the merge variable value in Browse, Find, and Preview modes, and when you print records.
To insert a merge variable onto a layout:
FileMaker recommends that you create global variables for use as merge variables.
For example, insert a merge variable into a text block or by itself on the layout.
Do not insert merge variables over a field or any other object that you want to view.
A placeholder merge variable (<<$$>>) appears on the layout.
Click between the $$ and >> symbols in the placeholder variable, then type the merge variable name (the name of the variable you created in step 1).
Important  To ensure that merge values are displayed accurately, each record must be refreshed as it is being browsed, previewed, or printed. You can refresh records manually by, for example, creating a “Refresh” button that calls the Refresh Window script step, or automatically by creating a script that includes the Refresh Window script step.
To create a merge variable named <<$$acctname>>, which displays the name of the user’s account, create the script step: Set Variable[$$acctname; Value: Get(AccountName)]. Then, insert the merge variable <<$$acctname>> on the layout.
To create a merge variable named <<$$POnum>>, which appends the text MPO” to the current record number to form a purchase order number, create the script step: Set Variable[$$POnum; Value: Get(RecordNumber) & “MPO”]. Then, insert the variable <<$$POnum>> on the layout.
To create a merge variable named <<$pp>>, which displays the number of pages in a report, create the following script:
Enter Preview Mode
Go to Record/Request/Page [Last]
Set Variable [$pp; Value:Get(PageNumber)]
Go to Record/Request/Page [First]
Pause/Resume Script [Indefinitely]
Then, in the layout footer, combine text, the page number symbol, and the merge variable:
Page ## of <<$pp>>
A variable used as a merge variable cannot include the repetition (index) number of a repeating field (as in the syntax $variable[repetition]) or a file path.
The value of a merge variable uses the attributes of the text block it is inserted into (or the layout’s default text attributes, if the merge variable was inserted onto the layout by itself). To change the text attributes of merge values, select the entire merge variable in Layout mode (including the <<, $$, and >> symbols), then select text formatting options. For more information, see Formatting text.
In Browse mode and Preview modes, a text block displays and prints only as much text as will fit within its dimensions. Because merge variables can display a variable amount of data, the contents of a text block may be clipped and may not appear in its entirety. If necessary, resize the text block to display all of the text. For information on resizing text blocks, see Resizing and reshaping objects.
Related topics 
Creating scripts to automate tasks
Using buttons with scripts