1.5

Table Of Contents
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. For a CSV/DB data type, the parameter it expects is simply the column name.
The region is then passed as a parameter to the get() method, which reads its contents
and converts it into an array of strings (because any region, even a CSV field, may
contain several lines).
l To "remember" the values that were processed the last time the event was triggered, we
use variables that remain available in between events. Note that these variables are
specific to the Boundary context and not available in any other scripting context in the
DataMapper.
l The script first checks if those values were initialized. If they weren't, it means this is the
first iteration so there's no need to compare the current values with previous values since
Page 219