Creating and managing layouts and reports > Drawing and inserting objects on a layout > Inserting merge variables onto a layout
 

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:

1. Create a variable using the Set Variable script step.

It's a good idea to create global variables for use as merge variables.

2. In Layout mode, click in the layout where you want to insert the variable, then choose Insert menu > Merge Variable.

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.

3. 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. If you need to refresh only one or a few objects in a window, use the Refresh Object script step.

Examples

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 display the current page number with the total number of pages in a report (for example, Page 1 of 10), start by creating a merge variable named <<$pp>>, and create the following script for it:

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, combine text, the page number symbol ({{PageNumber}}), and the merge variable on the layout header or footer:

Page {{PageNumber}} of <<$pp>>

Notes 

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.

You can also use a merge field to display data. See Placing merge fields on a layout.

You can also use a Get function instead of a global variable or merge variable. See Inserting the date, page number, or other variable onto a layout and Get functions.

Related topics 

Automating tasks with scripts

Working with buttons and button bars on layouts