Scripts
Scripts appear all over the place in TDI: they are used to customise error handling, to extend the functionality of existing components, and even to replace standard components where something special is required.
TDI scripts are written in
JavaScript. The documentation suggests that other languages can be used, but the release notes say that the facility to choose scripting language will go away in a future version.
There are six places where scripts are found, and the names are very similar so watch out!
Script components (SC)
These are simply empty assembly-line components where you can write a script. They are very useful for debugging, as you can insert code to dump selected data to the execution log and just disable the component when it is not needed. SCs are also handy debugging tools. By adding a call like
system.skipEntry() to the end of a Script component, and dragging the SC around in the AL, you control how much of the line is executed.
Script Library
In the left-hand pane of the Config Editor you will find an object labelled
Scripts - this is the
Script Library. Any scripts defined here can be dragged into the
assembly line where they will become Script Components inheriting their content from the copy in the library (until you edit them, which breaks the inheritance).
Scripts in the library can also be used as prologs in assembly lines: see the
Where to define JavaScript functions page for more information.
Scripted components (Connectors, Functions and Parser)
Each component type offers a scripted variant where you create the
interface logic yourself using
JavaScript.
For example, a scripted connector can operate in any of the normal connector modes (Iterator,
AddOnly, Delete, Lookup etc). When created, it has stub functions already provided which you can expand to do whatever you need. It has input and output maps as appropriate to the mode it is operating in.
Hooks
Assembly lines have hooks, connectors have hooks. They are waypoints in the built-in workflows provided by TDI where you can hang custom scripts. Use hooks to process exceptions, to log exceptions, or even to ignore errors (if you enable an error hook but do not put any code there you are effectively causing the error to be ignored since the script replaces the normal exception handler).
Advanced Mapping of attributes
Scripts can be used in Attribute Mapping components and in Input and Output maps. To do this, you just have to select
Advanced Mapping for the attribute concerned. Use the script to calculate the value of the attribute, and assign it to
ret.value
before returning from the script.
To be continued...
Scripts are simply blocks of script that can be dropped into an
AssemblyLine Feeds section. They support inheritance and have a Library Folder in the Config Browser.
Note that an AL has a single Script Engine, so if you register a variable in some script (like a Hook, Advanced Attribute Map or Script Component) then it is available to all scripts in the AL.
The only exception is for Scripted components, which live in their own Script Engine environments
.
--
EddieHartman - 7 July 200
8
This is a
GlossaryEntry