2022.2

Table Of Contents
Alternativelyyoucouldusean'Eachmatchedelement'script(see"Settingthescopeofascript"on
page813).
Yetanotherwayistocreateastandardforloopusingthetable'slengthproperty:
var records = record.tables.detail;
for (var i = 0; i < records.length; i++) {
var rec = records[i];
...
}
Examples
record.fields
ThefollowingStandardScriptevaluatesthedatafieldCountryinthecurrentrecord.Ifthevalueis
'CANADA'itwillshowtheresults,otherwiseitwillhidethem.(Theresultsobjectcontainstheelements
thatmatchthescript'sselector;see"results"onpage1301and"Writingyourownscripts"on
page808.)
if (record.fields["Country"] == "CANADA") {
results.show();
} else {
results.hide();
}
Insteadofrecord.fields["Country"]youcouldwriterecord.Country(casesensitive),ifthere
isnodetailtablewiththesamename.
InaControlScript,anentiresectioncouldbeenabledordisabledbasedonthesamecondition:
if (record.Country == "CANADA") {
merge.template.contexts.PRINT.sections["Section 1"].enabled = true;
} else {
merge.template.contexts.PRINT.sections["Section 1"].enabled = false;
}
(FormoreinformationaboutControlScripts,see"ControlScripts"onpage838.)
record.tables
Thenextscriptlooksupavalueinthefirstrecordinadetailtablecalled"detail"andshowsorhidesthe
resultsdependingonthatvalue.
if (record.tables.detail[0].fields.prod_id == "10") {
results.show();
} else {
results.hide();
}
Notethatindexesstartcountingat0,sotables.detail[0]referstothefirstrecordinthedetail
table.
Page 1201