1.8

Table Of Contents
Note
The first line is just the header with the names of the CSV columns. The data is already sorted per
year, per artist, and per album.
Your goal is to examine two values in each CSV record and to act when either changes. The
DataMapper GUI allows you to specify a On Change trigger, but you can only specify a single
field. So for instance, if you were to set the record boundary when the "Released" field
changes, you'd get the first four lines together inside a single record. That's not what you want
since that would include albums from several different artists. And if you were to set it when the
"Artist" field changes, the first few records would be OK but near the end, you'd get both the Led
Zeppelin 3 and led Zeppelin 4 albums inside the same record, even though they were released
in different years.
Essentially, we need to combine both these conditions and set the record boundary when
EITHER the year OR the artist changes.
Here's what the script would look like:
/* Read the values of both columns we want to check */
var zeBand = boundaries.get(region.createRegion("Artist"));
var zeYear = boundaries.get(region.createRegion("Released"));
/* Check that at least one of our variables holding previous values
has been initialized already, before attempting to compare the
values */
if (boundaries.getVariable("lastBand")!=null) {
if (zeBand[0] != boundaries.getVariable("lastBand") || zeYear[0]
!= boundaries.getVariable("lastYear") )
{
boundaries.set();
}
}
boundaries.setVariable("lastBand",zeBand[0]);
boundaries.setVariable("lastYear",zeYear[0]);
l The script first reads the two values from the input data, using the createRegion() method
(see: "Example" on page285). For a CSV/database data type, the parameter it expects is
Page 259