Branch components affect the order in which the other components,
such as, Connectors, Scripts, Functions, AttributeMaps and other Branch
components, are executed in the Flow of the AssemblyLine.
Overview
Branch components come in three varieties:
- Simple (also
called just Branch)
- Loops (Branches
that loop)
- Switches (Branches
that share the same expression)
Branches can appear anywhere in the Flow section, but there is
no library folder for them in the Resources section of your workspace.
A
Branch does not have to run to completion; the same script call is
used to programmatically exit any type of Branch: system.exitBranch().
See Exiting a Branch (or Loop or the AL Flow) for more information.
The
three Branch component types are:
- Branch
-
While each type of Branch lets you define alternate routes
for AssemblyLine processing, this simplest form determines the action
in case: "If this situation occurs, then take this action." You define
what "situation occurs" means by setting up Conditions that must be
met; for example, by comparing data values or checking the result
of some operation. If the conditions are true, the components attached
under this Branch are executed.
The Branch allows you to define
Conditions based on any data in the TDI server: Attribute values,
parameters settings, externally accessible properties, and any information
available using JavaScript, such as operating
system calls for disk or memory usage. Multiple Conditions are ANDed
or ORed, depending on the Match Any check box setting.
This
simplest form of Branch component also supports three subtype settings,
IF, ELSE-IF and ELSE, that you can select.
- IF
- Can appear anywhere within the AssemblyLine Flow, the IF Branch
provides an alternative track for process to follow if Conditions
are true. Once the components under the Branch are executed, control
passes to the first component after this Branch. If you do
not want this to happen, you must either add an ELSE or ELSE IF Branch,
or exit the Branch with a scripted call to system.exitBranch().
- ELSE-IF
- Identical to the IF Branch, except it can only appear immediately
following an IF or ELSE-IF Branch.
- ELSE
- Can only appear immediately after an IF or ELSE-IF Branch, the
ELSE Branch has no Conditions. Its components are processed only if
no preceding IF or ELSE-IF Branch was true. Furthermore, the ELSE
instance always evaluate to true so there are no conditions evaluated
during the cycle.
As mentioned above, you can prematurely exit a
Branch by means of scripting, using system.exitBranch().
- Loop
-
The Loop component provides functionality for adding cyclic
logic within an AssemblyLine. Loops can be configured for three modes
of operation: based on Conditions, based on a Connector or based on
the values of an Attribute:
- Conditional
- Just as with a simple Branch, you can define Conditions that control
Loop behavior. The Loop will continue to cycle as long as the Conditions
are met, and will stop as soon as they fail. The details window for
Loops is the same as for the simple Branches described in the previous
section.
- Connector
- This method lets you set up a Connector in either Iterator or
Lookup mode, and will cycle through your Loop flow for each entry
returned. The details window of this type of Loop contains the Connector
tabs necessary to configure it, connect and discover attributes and
set up the Input Map.
Note that you have a parameter called
Init
Options with which you can instruct the AL to either:
- Do Nothing means that the Connector will not be prepared
in any way between AL cycles.
- Initialize and Select/Lookup causes the Connector to be
re-initialized for each AL cycle.
- Select/Lookup Only keeps the Connector initialized, but
redoes either the Iterator select or the Lookup, depending on the
Mode setting.
Note also that there is a Connector Parameters tab,
which functions similarly to an Output Map in that you can select
which Connector parameters are to be set from work Attribute
values.
This brings us to the topic of how Looping with an
Iterator differs from doing so based on Lookup mode. Both options
perform searches that create a result set returned for looping.
For Iterator mode, the result set is controlled exclusively by the
parameter settings of this component. Lookup mode, on the other hand,
uses Link Criteria to define search or match rules. Since it frees
you from having to code Hooks like On No Match or On Multiple Found,
this is the preferred way of doing searches that may not always return
one (and just one) matched entry.
- Attribute Value
- By selecting any Attribute available in the work Entry, the Loop
flow will be executed for each of its values. Each value is passed
into the Loop in a new Work Entry attribute named in the second parameter.
This option allows you to easily work with multi-valued attributes,
like group membership lists or e-mail.
You can prematurely exit a Loop by means of
scripting, using system.exitBranch().
- Switch
- Unlike expressions used in the Conditions of Branches and Loops,
the Switch expression can result in more values than just true or false.
For example, you could Switch on the value of an Attribute, or the
operation requested when this AL was called from another AssemblyLine
or process. Under the Switch component, you add a Case for each constant
value of the Switch expression that you want to handle. So for example,
if you set up the Switch to use the delta operation code in the Work
Entry, your Cases would be for values like "add", "delete" and "modify."
In
an AL Switch-Case construct, multiple cases can be active at the same
time. TDI checks each case, just as it would a series of standard
IF Branches. The following example shows how multiple cases work:
work.setAttribute("test","abc");
Switch work.test
Case startsWith("a"): this is true
Case contains ("bc"): this is true
Case length=3: this is true
The three Switch work.test expressions that
are true will trigger Switch execution.
You can prematurely
exit a Switch-Case by means of scripting, using system.exitBranch();.