Scripting

Script Editor

Script editor allows customizing data extraction process by adding user-defined scripting procedures performed on a number of internal predefined events (context methods). The custom scripts provide access to such internal TextConverter resources as input and output dictionary fields, properties and objects, as well as  and functional libraries 

  1. Access input and output fields

  2. Add and access Target variables including data objects connected to additional external data sources

  3. Take advantage of built-in Target platform objects, libraries and conventional scripting resources 

TextConverter Script Editor

The following Context Methods are available for using in the script:

#

Context Method

Auto

Manual/
Delimited

Frequency of Calls

Description

1.      

OnSetup

+

+

Once

Called before processing started. Used for input and output files programmatic initialization.

2.      

OnStartProcess

+

+

Once or once per input file in case of batch processing

Called before the first input record is processed. Used for any processing initialization.

3.      

OnInputField(template, field, code)

+

 

Multiple

Allows to create scripted definitions of the following tag field properties:

Code       Property
tag           Search tag
ttag          Top tag
btag         Bottom Tag
skip          Skip Line or Skip From
skipto      Skip To

A corresponding field property should be marked as <script> in order for this method to get called.
OnInputField should return true if a requested property was recognized.
Search tag script should also return a starting position and a width of a found tag through a call to template.SetTag. It can also return a tag field value by calling template.SetTagFIeld. The option indicator in this case should be <script_val>.

4.      

OnInputLine

+

 

Multiple

Called on processing each input line. Used for custom parsing.

5.      

OnInputRecord(template)

+

 

Multiple

Called when a segment of input lines is recognized as belong to an input template. Most useful in conjunction with Detailed Manual templates.

6.      

OnTemplate(template, code)

+

 

Multiple

Allows to create scripted definitions of the following input template properties:

Code       Property
trange     Top Range
brange    Bottom Range
skip         Skip Line or Skip From
skipto      Skip To

A corresponding template property should be marked as <script> in order for this method to get called.
OnTemplate should return true if a requested property was recognized.

7.      

OnOutputRecord

+

 

Multiple

Called before generating output record. Used for implementing custom data transformations.

8.      

IsNewRecord

 

+

Multiple

Called on each input line. Used for implementing arbitrary record delimiters.

9.      

OnRecord

 

+

Multiple

Called on each input line. Used for implementing manual parsing rules.

10.    

OnFinishProcess

+

+

Once

Called after the last input record is processed. Used for implementing post one input file processing actions.

11.    

OnFinishBatch

+

+

Once

Called after the batch processing is finished. Used for implementing post processing actions.

To search the script being edited press CTRL+F and a search dialog will appear. To search and replace, press CTRL+H. 



TextConverter allows you to use all of VBScript together with a set of high level objects specific to data extraction and the preparation and conversion of structured data.

1.  Start by defining your output dictionary.  You can load the dictionary automatically from an existing database table simply by connecting to the table or you can use the visual interface to add each field.  If you need multiple output tables (or files), just add variables called data objects in the pane to the left of the scripting area.

2.  Next, start scripting.  Right click on a field in the output dictionary and follow the context menu down to select "Create Script Conversion" item, the OnRecord context method will be inserted with a line of code for the corresponding field customization:

'----------------- OnRecord -----------------

Function OnRecord

DictOut.Price10.value = Value

End Function

3.  From here you can replace the placeholder word "Value" to assign any syntactically correct value to the filed in the output dictionary.  You can assign a static value, a value derived from a field in the input dictionary, or any value that can be created given the input data and a set of programmatic rules.  Note that fields in the output dictionary can be referenced by either their name or position in the order of fields.

Scripting takes place in the script pane of the user interface.  Scripting is a powerful, yet simple tool to achieve unlimited flexibility in text data conversion.

To customize certain aspects of the conversion process, you can implement several context methods which are called by TextConverter during the conversion process. You decide which methods should be implemented depending on your needs. In most customization tasks, implementing just OnRecord method would suffice.

Scripting resources can be grouped into the following categories:

Context methods - Implement context methods to customize different phases of the conversion process, such as the start of the process, processing of an input record, the end of the process, etc.  Context methods are obtained by right clicking in the script editor or variables pane.

.This methods - are a set of methods, including some very useful functions, implemented by the TextConverter object.  This methods are obtained by typing "this." in the script editor then selecting from the list of methods.  The .this methods are specific to TextConverter and are not available in TARGET Reports or other TARGET applications outside of TextConverter.

.TARGET methods
- are a set of utility methods implemented by the TARGET object facilitate some useful common tasks like parsing text data into elements, working with arrays, etc.  TARGET methods are obtained by typing "target." in the script editor then selecting from the list of methods.  The .target methods and functions are available through both TextConverter and TARGET Reports, as well as, other TARGET applications.  NOTE:  "trg" also works as a shortcut for the target object
 
Variables - A pre-built set of objects (variables), which allow you to extend the text conversion functionality by connecting to additional input and output data sources, including files and database tables, exposing your internal script objects for an external automation, etc.  Variables are obtained by right clicking in the variables pane (the left section of the script editor).

VBScript - Virtually all of the VBScript's capabilities, VBScript's Libraries, and VBScript's external object's are available for use inside of TextConverter using the scripting pane and outside of TextConverter using TextConverter's API.


Related Sections

Script Editor

Data Object User Interface

TextConverter's Concept

Setting up a Conversion: Step by Step

Samples and Walkthroughs

Automation