2022.2

Table Of Contents
Bysettingthescopeofascriptyoucandeterminewhetheryouwanttorunthescriptonce,oronce for
each elementthatmatchestheselector.(See"Settingthescopeofascript"onpage813.)
Ifascriptrunsonce,accessingthedetaildataanddynamicallyaddedrowstendstobeabitcom-
plicated,especiallywhentheyarenested,sinceitinvolvesloopingovertheresultsandrecordobjects
(see"results"onpage1301and"record"onpage1199).
Ifascripttargets(somethingin)arowthatisboundtoadetailtable,andrunsonce for each matched
element,thecurrentelementisaccessibleviathethisobject(see"this"onpage1237)andthecurrent
detailrecordisaccessibleviathis.record.
Theadvantageofthelatterapproachisdemonstratedinanexamplebelow.
Quick-startascriptwiththeCreatescriptbutton
Thisquick-startprocedureonlyworksforelements(acellorspan)thathaveadirectlinkwithadata
field.
Tofindoutwhetheracellorspanhasadirectlinktoadatafield,selectit(see"Selectinganelement"
onpage570)and:
l
TakealookontheAttributespane.IfunderOther,theFielddrop-downorSumfieldpointtoa
datafieldinthedetailtable,theelementhasadirectlinktoadatafield.
l
SwitchtotheSourceview.Elementswithadirectlinktoadatafieldhaveadata-fieldor
data-sumattribute.
Bydefault,cellsthatarefilledwithaplaceholderhaveadirectlinkwithadatafield.Cellsthatarefilled
withanexpressiondon't.Tocreateadirectlinkwithadatafield,selectthecellandchoosethedata
fieldfromtheFielddrop-downontheAttributespane.
Theeasiestwaytoaddascriptthattargetsaspecificelement(acellorspan)thathasadirectlinkwith
adatafieldisthis.
1. InDesignmode,selecttheelement.
2. ClicktheCreate ScriptbuttonnexttotheFielddrop-downontheAttributespane.
3. ClickYestoconfirmthatthedirectlinkwiththedatafieldwillbebroken.
Asaresult:
l
Theelementwillnowhaveadata-scriptattribute.
l
Thedata-fieldordata-formatattributeisremoved.
l
AnewscriptwillbecreatedandopenedintheScriptEditor.
Theselectorofthenewscriptisthedata-scriptattributewiththenameofthedatafieldthattheele-
mentwaslinkedtoasitsvalue.Forexample:table[data-script='ID'].
Page 836