2022.2

Table Of Contents
if (boundaries.getVariable("lastBand")!=null) {
if (zeBand[0] != boundaries.getVariable("lastBand") || zeYear[0] != bound-
aries.getVariable("lastYear") )
{
boundaries.set();
}
}
boundaries.setVariable("lastBand",zeBand[0]);
boundaries.setVariable("lastYear",zeYear[0]);
l
Thescriptfirstreadsthetwovaluesfromtheinputdata,usingthecreateRegion()method(see:
"createRegion()"onpage395).ForaCSV/databasedatatype,theparameteritexpectsissimply
thecolumnname.Theregionispassedasaparametertotheget()method,whichreadsitscon-
tentsandconvertsitintoanarrayofstrings(becauseanyregion,evenaCSVfield,maycontain
severallines).
l
To"remember"thevaluesthatwereprocessedthelasttimetheeventwastriggered,weusevari-
ablesthatremainavailableinbetweenevents.Notethatthesevariablesarespecifictothe
BoundarycontextandnotavailableinanyotherscriptingcontextintheDataMapper.
l
Thescriptfirstchecksifthosevalueswereinitialized.Iftheyweren't,itmeansthisisthefirstiter-
ationsothere'snoneedtocomparethecurrentvalueswithpreviousvaluessincetherehave
beennoneyet.Butiftheyhavealreadybeeninitialized,thenaconditionchecksifeitherfieldhas
changedsincelasttime.Ifthat'sthecase,thenaboundaryiscreatedthroughtheset()method.
l
Finally,thescriptstoresthevaluesitjustreadinthevariablesusingthesetVariables()method.
Theywillthereforebecomethe"lastvaluesencountered"untilthenexteventgetsfired.When
called,setVariables()createsthespecifiedvariableifitdoesn'talreadyexistandthensetsthe
valuetothesecondparameterpassedtothefunction.
Youcantryityourself.PastethedataintothetexteditorofyourchoiceandsavethefiletoAlbums.csv.
ThencreateanewDataMapperconfigurationandloadthisCSVasyourdatafile.IntheDataInputSet-
tings,makesureyouspecifythefirstrowcontainsfieldnamesandsettheTriggertoOn script.Then
pastetheaboveJavaScriptcodeintheExpressionfieldandclicktheApplybuttontoseetheresult.
Basic example using a text file
Thisexampleissimilartothepreviousexample,butnowthedatasourceisaplaintextfilethatlooks
likethis:
Beatles AbbeyRoad 1969
Beatles YellowSubmarine 1968
LedZeppelin LedZeppelin1 1969
LedZeppelin LedZeppelin2 1969
Page 367