2022.2

Table Of Contents
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844and"Writingyourownscripts"onpage368.)
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"onpage398.)
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.
results
Theresultsobject(type:QueryResults)istheresultofthequeryforHTMLelementsthatmatch
theselectorofthescript.TheselectorofascriptcanbespecifiedintheScriptEditorandisvisiblein
thesecondcolumnoftheScriptspane,nexttothenameofthescript.
If,forexample,ascriptwouldhavetheselectorp.onlyCanada,thescriptwouldapplytoallpara-
graphsthathavetheclassonlyCanada.(ClassescanbedefinedintheAttributespaneattheright:
selecttheelementinthecontentandtypetheclass(es)intheClassfield.)
Page 745