Boundaries using a2 columns from CSV/XLSX, but only the first 5 characters from the first column.
Using the example, but can’t seem to only use the first 5 characters.
/* Read the values of both columns we want to check */
var zeRef = boundaries.get(region.createRegion("Ref#"));
var zeShip = boundaries.get(region.createRegion("Shipment Category"));
/* Check that at least one of our variables holding previous values has been initialized already, before attempting to compare the values */
if (boundaries.getVariable("lastRef")!=null) {
if (zeRef[0] != boundaries.getVariable("lastRef") || zeShip[0] != boundaries.getVariable("lastShip") )
{
boundaries.set();
}
}
boundaries.setVariable("lastRef",zeRef[0]);
boundaries.setVariable("lastShip",zeShip[0]);
If I perform the substr within the IF, I get mostly what I’m looking for.
So partially there, but not getting the second bit correct though.
If the Ref# value (only the first 5 characters) match and the Shipment Category match, then they would all be in a record.
/* Read the values of both columns we want to check */
var zeRef = boundaries.get(region.createRegion("Ref#"));
var zeShip = boundaries.get(region.createRegion("Shipment Category"));
/* Check that at least one of our variables holding previous values has been initialized already, before attempting to compare the values */
if (boundaries.getVariable("lastRef")!=null) {
if (zeRef[0].substr(1,5) != boundaries.getVariable("lastRef").substr(1,5) && zeShip[0] != boundaries.getVariable("lastShip") )
{
boundaries.set();
}
}
boundaries.setVariable("lastRef",zeRef[0]);
boundaries.setVariable("lastShip",zeShip[0]);
Ok, so sticking with the scripted boundaries, then…
You don’t have to compare two values separately. Concatenate them and store the concatenated value into a single variable. That’s what you compare the next values to for each line of the file:
var fld1 = boundaries.get(region.createRegion("FIRSTFIELD"));
var fld2 = boundaries.get(region.createRegion("SECONDFIELD"));
var newRef = fld1[0].substr(1,5) +fld2[0];
if (boundaries.getVariable("lastRef")!=null) {
if(newRef!==boundaries.getVariable("lastRef") ) {
boundaries.set();
}
}
boundaries.setVariable("lastRef",newRef);
This seems to work perfectly with my small sample excel file.
I scared me for a second as initially it didn’t return any data.
I closed the datamapper and reopened it and it worked as expected.
I was in the process of attempting the same notion after your preprocessor post gave me the idea.