1.6

Table Of Contents
Note
The first line is just the header with the names of the CSV columns. Obviously, 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, then you'd get the first four lines together inside a single record, but 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, then 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 on different years. So that's no good either.
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
have 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() API
method (see: "createRegion()" on page242.) For a CSV/DB data type, the parameter it
Page 223