2022.2

Table Of Contents
1. AddafieldtoanExtractstep,preferablybyextractingdatafromoneofthepossibleregions;see
"Extractingdata"onpage229.Toaddafieldwithoutextractingdata,see"Expression-based
field"onpage265.
2. OntheSteppropertiespane,underFieldDefinition,selectthefieldandchangeitsModeto
Javascript.
IfthefieldwascreatedwithitsModesettoLocation,youwillseethatthescriptalreadycontains
onelineofcodetoextractdatafromtheoriginallocation.
3. Expandthescript.Startbydoingthecheck(s)todeterminewherethedatathatneedstobe
extractedislocated.Usethedata.extract()functiontoextractthedata.Theparametersthat
thisfunctionexpectsdependonthedatasource,see"extract()"onpage375.
Example: ThefollowingscriptextractsdatafromacertainregioninaTextfile;let'sassumethat
thisregioncontainstheunitprice.Iftheunitpriceisempty(aftertrimminganyspaces),the
productdescriptionhastobeextractedfromtwolines;elsetheproductdescriptionshouldbe
extractedfromoneline.
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parameteroftheextract()functioncontainstheheightoftheregion.Whenworking
withaTextfile,thisequalsanumberoflines.
WithaTextfile,thedata.extract()methodaccepts0asitsheightparameter.Withtheheight
setto0itextractsalllinesstartingfromthegivenpositionuntiltheendoftherecord.
NotethatthisscriptreplicatesexactlywhatcanbedoneinaConditionstep.Incaseslikethis,itis
recommendedtouseaConditionstep.Onlyuseascriptwhennostepsaresufficienttogivetheexpec-
tedresult,orwhentheextractioncanbebetteroptimizedinascript.
Steps
IntheDataMapper,stepsarepartofanextractionworkflow(see"Datamappingworkflow"on
page221).TheycontainaspecificinstructionfortheDataMapper,forexampletoextractdata,createa
loop,orapplyacondition.Sometypesofstepsarecontainersforothersteps.
Thesteps,displayedonthe"Stepspane"onpage321,areexecutedsequentially,fromtoptobottomin
anextractionworkflow.
InsideaConditionstep,somestepsmaybeskippedaltogetherwhentheyareonaparticularbranch,
whereasinaRepeatstep-aloop-severalstepsmayberepeatedanumberoftimes.
Page 248