2021.2

Table Of Contents
The following script (with the selector p) changes the text color of all paragraphs to red with a
single line of code:
results.css('color', 'red')
It does this for each and every customer, because it does not depend on a value from the record
that is being merged to the template.
Using values from the record in a script
To access the record that is being merged to the template when the script runs, use the object
record.
Suppose you want to display negative amounts in red and positive amounts in green.
Assuming that there is an AMOUNT field in your customer data, you could write the following
script (with the selector: td.amount, that is: table cells with the class 'amount').
var amount = record.fields.AMOUNT;
if (amount >= 0)
{results.css('color', 'green');}
else if (amount < 0) {
results.css('color', 'red');
}
When this script executes, it stores the value of the AMOUNT field from the current record in a
variable and evaluates it. If the value is zero or higher, the color of text in the results - the table
cells in this case - will be set to green; if the value is below zero, the text color will be set to red.
Tip
For more examples of using conditions, see this how-to: Combining record-based
conditions.
If an expanded script contains errors or if there are warnings, icons appear in the overview ruler
on the right hand side of the editing area. These icons are shown relative to their position in the
script and do not move as you scroll down. You can click on an icon to quickly jump to the error
or warning. Script errors are highlighted by a red icon, and warnings in yellow. The topmost
icon will display red if any errors exist in the script at all.
Page 882