2018.2

Table Of Contents
Take the following JavaScript function, for example:
function myAddFunction(p1, p2) {
return p1 + p2;
};
If this is saved as myFunction.js and imported, then the following would work anywhere in the
configuration:
var result = myAddFunction(25, 12); // returns 37!
Setting boundaries using JavaScript
As soon as you select the On Script option as the trigger for establishing record boundaries
(see "Record boundaries" on page180), you are instructing the DataMapper to read the source
file sequentially and to trigger an event each and every time it hits a delimiter. (What a delimiter
is, depends on the source data and the settings for that data; see "Input data settings
(Delimiters)" on page178).
In other words, the script will be executed - by default - as many times as there are delimiters in
the input data.
If you know, for instance, that a PDF file only contains documents that are 3 pages long, your
script could keep count of the number of times it's been called since the last boundary was set
(that is, the count of delimiters that have been encountered). Each time the count is a multiple of
3, it could set a new record boundary. This is basically what happens when setting the trigger to
On Page and specifying 3 as the Number of Pages.
Note
Remember that a boundary script is being called on each new delimiter encountered by
the DataMapper parsing algorithm. If for instance a database query returns a million
records, the script will be executing a million times! Craft your script in such a way that it
doesn't waste time examining all possible conditions. Instead, it should terminate as soon
as any condition it is evaluating is false.
Page 323