2022.2

Table Of Contents
Tofindoutwhetheracellorspanhasadirectlinktoadatafield,selectit(see"Selectinganelement"
onpage174)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'].
Thecodeofthescriptreplacesthecontentsoftheelementwiththecurrentvalueofthedatafield:
var field = this.record.fields['ID'];
if (field) {
this.text(formatter.upperCase(field));
}
UnderOptions,thescopeofthescriptissettoEach matched element(see"Settingthescopeofa
script"onpage373).Thismeansthatinthecode,thisreferstotheelementthatmatchestheselector,
andthis.recordreferstothecurrent (nested) detail record(see"this"onpage781).
Tip: Togetaccesstotherowinwhichthecellislocated,youcanusethis.parent().
Note: Ifyoubindtheelementtoadatafieldagainbyselectingitandthenselectingafieldfrom
theFielddrop-downontheAttributespane,thedata-scriptattributewillberemoved.
Page 396