2022.1

Table Of Contents
In order to loop over records in a detail table you could use a for(... in ...) loop (see "for(... in ...)"
on page1348), for example:
var records = record.tables.detail;
for (var i in records) {
var rec = records[i];
...
}
Alternatively you could use an 'Each matched element' script (see "Setting the scope of a
script" on page924).
Yet another way is to create a standard for loop using the table's length property:
var records = record.tables.detail;
for (var i = 0; i < records.length; i++) {
var rec = records[i];
...
}
Examples
record.fields
The following Standard Script evaluates the data field Country in the current record. If the value
is 'CANADA' it will show the results, otherwise it will hide them. (The results object contains the
elements that match the script's selector; see "results" on page1509 and "Writing your own
scripts" on page918.)
if (record.fields["Country"] == "CANADA") {
results.show();
} else {
results.hide();
}
Instead of record.fields["Country"] you could write record.Country (case sensitive), if there
is no detail table with the same name.
In a Control Script, an entire section could be enabled or disabled based on the same
condition:
if (record.Country == "CANADA") {
merge.template.contexts.PRINT.sections["Section 1"].enabled =
Page 1383