I have some data records presented as line print. I am splitting on FF. If I have a page with less than 10 lines in I need to remove it from my output files. Will it be best to do this in the datamapper or the workflow? I’m struggling to find a way of doing this.
You don’t need to remove the records from the data files, you simply need to skip them in the DataMapper. At the very top of your data mapping process, you insert a condition and in the True branch of that condition, you add a JavaScript Action step and set its action to Stop Processing Record, which instructs the process to immediately move on to the next record.
Now there is no way currently to know how many lines a record contains, but your condition can use some JavaScript code to achieve the same result. For instance, the following code will attempt to jump to line 11 and if that generates an error, then the condition will be deemed true (and since the error is trapped and handled, it won’t cause any issue with your process:
var curPos = steps.currentPosition;
var returnValue = false;
try {
steps.moveTo(0, 11);
// If this works, then there are at least 10 lines in the record
} catch(e) {
// If an error occurs, then there are no more then 10 lines in the record
returnValue = true;
}
steps.moveTo(1,curPos);
returnValue;
A simplified DM config using this method would look like this. Note how the condition needs to appear before any extraction step:
The data file is a PDF file. The data file has 4 pages (but can have more 20, 30…), Page 1 is a cover page and last page is an end cover page. I have a text condition to split the record on the text “Some Text 5”. So for this example, 2 records will be created. As I can skip the first record, the last page (page 4) will be included the in the 2nd record. Record 2 will have pages 2-4. How can I prevent the last page from being added/included via datamapper?
That’s a bit more tricky because you need to eliminate the last page of a record, but only if that record is the last one in your data. So in that instance, I would recommend instead that you delete that last page from the input data file before feeding it to the DataMapper.
There is an example of using a script in Workflow to delete a PDF page in this post, you could adapt it easily to remove the very last page of the PDF. In your case you’d replace the line
Thanks @Phil, was actually looking at that post before posting here.
I’m a bit surprised that the datamapper has the skip record action but no skip page/data page action. Anything of this feature request put through yet?
Well there is a Skip To Next Record option, as well as an End data mapping option, both of which would work in your case. So you could add an Action Step at the appropriate spot in your DM flow, but you would only want it to run for the very last page of the very last record.
And that’s where it gets tricky: you know when you’re on the last page of any record (i.e. when steps.CurrentPage == steps.totalPages ) but you don’t know when you’re on the last record.