1.8

Table Of Contents
1. Add a field to an Extract step, preferably by extracting data from one of the possible
regions; see "Extracting data" on page118. To add a field without extracting data, see
"JavaScript-based field" on page156.
2.
On the Step properties pane, under Field Definition, select the field and change its Mode
to Javascript.
If the field was created with its Mode set to Location, you will see that the script already
contains one line of code to extract data from the original location.
3. Expand the script. Start by doing the check(s) to determine where the data that needs to
be extracted is located. Use the data.extract() function to extract the data. The
parameters that this function expects depend on the data source, see "Examples" on
page271.
Example
The following script extracts data from a certain region in a Text file; let's assume that this
region contains the unit price. If the unit price is empty (after trimming any spaces), the product
description has to be extracted from two lines; else the product description should be extracted
from one line.
var s = data.extract(1,7,1,2,"");
if (s.substring(1,3).trim().length == 0)
{ data.extract(12,37,0,2,""); } /* extract two lines */
else { data.extract(12,37,0,1,""); } /* extract one line */
The fourth parameter of the extract() function contains the height of the region. When working
with a Text file, this equals a number of lines.
Tip
With a Text file, the data.extract() method accepts 0 as its height parameter. With the height set to 0
it extracts all lines starting from the given position until the end of the record.
Note that this script replicates exactly what can be done in a Condition step. In cases like this, it
is recommended to use a Condition step. Only use a script when no steps are sufficient to give
the expected result, or when the extraction can be better optimized in a script.
Page 139