OL Learn

Data Map 2-column Text File

I’m struggling today, and could use a nudge. I have data that is preformatted for 2-up labels. 8 lines per “pair” of records. One address is column 1 - 50, the second address is column 51 - 100.

I can capture both “labels” into a single data model record (two extract steps). But how to capture one address per record?

I don’t mind a single record with each address in a detail table record, if that’s the most viable approach.

I basically need to capture rows 1-8, columns 1-50, then move back up eight rows and over 50 spaces, capture the next 8 lines, then move back and down, etc.

1 2
3 4
etc.

Maybe run two passes of datamapping? First datamap left column, store recordset_id, then datamap right column, store the second recordset_id. Now run retrieve items to get both recordsets and from then follow as usual

1 Like

How about running a preprocessor to “re-arrange” the records so that the one one the right is repositioned “under” the one on the left, and then doing that for the entire file? That way, you’d just have to set your DM to cut after 8 lines and that would be it. Here’s some code that seems to work just fine for me:

var inF = openTextReader(data.filename);
var outF = openTextWriter(data.filename+'.tmp');

var lineLeft="", lineRight = "", lineCount=0;

while ((oneLine=inF.readLine())!=null) {
  lineLeft += oneLine.slice(0,50)+"\n";
  lineRight += oneLine.slice(50)+"\n";
  lineCount++;
  if(lineCount>7) {
	outF.write(lineLeft);
	outF.write(lineRight);
	lineCount=0;
	lineLeft = "";
	lineRight="";
  }
}
outF.write(lineLeft);
if(lineLeft) outF.write("\n".repeat(8-lineCount));
outF.write(lineRight);
if(lineRight) outF.write("\n".repeat(8-lineCount));

inF.close();
outF.close();
copyFile(data.filename+'.tmp',data.filename);
1 Like

Thanks to both of you. I went with Phil’s solution. I tend to forget that I can add a preprocessor script directly to the Data Map.

This approach works best for me because, for this client agency, we use a single Workflow Process that uses the incoming data file name to derive/set the data map and template names. We didn’t want to create a new special process with two data maps, etc.