We currently have a datamapper that maps a text file where the boundary is set on the change of data in a field ie an ID.
Each record is its own ID number. In most cases, record sizes are 1-4 lines which allows us to create a nice design. However, some records are up to 13 lines which wrap onto a new page. We do not want a new page.
Is it possible to limit the record size to 10 lines and force a new record of 3 lines even though the boundary is set on unique ID’s?
You’ll have to use a script to set your boundaries because you’re combining 2 conditions (i.e. “find the ID” OR “number of lines is greater than 10”).
In the Settings panel:
In the Input Data section
Set the Page Delimiter type to On Lines
?Tick the Cut on number of lines option and set its value to 1 This will cause the script to be triggered on every single line in the file, which is what we want so we can examine its content and count the number of lines at the same time.
In the Boundaries section
Set the Trigger to On script
Add the following script:
// THIS script looks for the word RECORD at the beginning of a line
// First, create a line counter and increment it by one
var curIndex = boundaries.getVariable("lineIndex");
if (!curIndex) {
curIndex=1;
} else {
curIndex+=1;
}
// Then, read the first 6 characters of the line ("RECORD" is 6 letters)
oneLine=region.createRegion(1,1,6,1);
var allText = boundaries.get(oneLine);
// Now check if the word RECORD was found or if lineIndex > 9
if((curIndex>9) || (allText[0].trim()=="RECORD")){
// One of the conditions was met, set a new document boundary and reset
// counter to 0
boundaries.set(0);
curIndex = 0;
}
boundaries.setVariable("lineIndex",curIndex);
Obviously, you’ll have to adjust the script according to your requirements but this one should help you get started.
This is beautiful. I find it very helpful. However, I am looking at making it a bit more dynamic.
You capture the first 6 characters of a line :
oneLine=region.createRegion(1,1,6,1); var allText = boundaries.get(oneLine);
Now, i don't to compare it against a static string. I want to be able to compare it to the next line or the previous line to start a new record.
I have tried _region.createRegion(1,2,6,2)_ to try and grab the next line, however, that does not work.
I have even tried to assign the oneLine to a temporary variable to compare to the next line that is grabbed to no avail:
// THIS script looks for the word RECORD at the beginning of a line
// First, create a line counter and increment it by one
var curIndex = boundaries.getVariable(“lineIndex”);
if (!curIndex) {
curIndex=1;
} else {
curIndex+=1;
}
// Then, read the first 6 characters of the line (“RECORD” is 6 letters)
oneLine=region.createRegion(1,1,6,1); var temp = “”;
if (temp.length() == 0) {
temp = oneLine;
}
var allText = boundaries.get(oneLine); var allText2 = boundaries.get(temp);
// Now check if the word RECORD was found or if lineIndex > 9
if((curIndex>14) || (allText[0].trim()!= allText2[0].trim())){
// One of the conditions was met, set a new document boundary and reset
// counter to 0
boundaries.set(0);
curIndex = 0;
} temp = oneLine;
boundaries.setVariable(“lineIndex”,curIndex);
You can’t grab the next line with this configuration. Here’s why:
The Boundary Script runs for each “page” that is being parsed by the DataMapper. When the script runs, it has access to the entire page. But since we are setting the Page Delimiters to 1 line, it means that entire page contains… well, a single line. Which means you can’t examine two lines at the same time.
What you should do is store the content of your line in a Boundary variable , using boundaries.setVariable(), just like the Counter variable already does. You have to use boundary variable because those are carried over from one iteration of the script to the next, while native javascript variables are not.
The next time the script runs (i.e. on the next line), compare the content of that line with the value of the boundary variable that was set previously. If there’s a match, reset the variable to this new value and then set the boundary using ?boundaries.set(-1) or boundaries.set(0) or boundaries.set(1), ?depending on whether the boundary should be placed before, respectively, the previous line, the current line or the next line.
You could be tempted to set your Page Delimiters to more than one line, to save you the hassle of having to store the value in a variable, then compare that with the next line, etc… But that won’t work because the Boundary must always occur on a page delimiter (not on any arbitrary line).