Appearance
Decision router
Routes each record to one of several branches. A C# script returns a route name for the record; the record is sent to the outgoing connections whose route id equals that name. Use it for if/else and switch-like branching.
Pins
| Pin | Kind | Types | Description |
|---|---|---|---|
| Input | input | any | Records to route. |
| Output | output | same as input | The unchanged input record. Draw one connection per branch from this pin and set the connection's route id (connection properties) to the route name. |
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
Condition | string (C# code editor) | generated template | C# code containing the method GetRoute (see below). |
The Condition script
The script is the body of a class; it must contain exactly this method:
csharp
public string GetRoute(IMetaData metaDataInstance, IViaType inputDataInstance)
{
var metaData = (MyFlowNamespace.FlowMetaData)metaDataInstance;
var inputData = (MyFlowNamespace.Order)inputDataInstance;
if (inputData.Amount > 1000) return "Large";
return "Small";
}- The returned string is the route name. It is compared exactly (case-sensitive) with the route id of each outgoing connection.
- The template generated by the designer casts the metadata to the flow's
FlowMetaDataand the input to the input connection's type; adjust the cast when the input type changes. usingstatements can be written anywhere in the script; they are moved to the top. Common namespaces (System,System.Linq,System.Collections.Generic,Viaducta.TypeSystem,Viaducta.TypeSystem.Metadata,Viaducta.Plugin.Design, the flow namespace, ...) are already imported. NuGet packages of the flow can be used.- The property
Services(IFlowService) is available in the script for logging, flow properties, etc.
Behaviour
- For each record a new script instance is created,
GetRouteis called and the result is stored as the record's route id; the record is then sent toOutput. - Delivery from
Output:- connections with a route id receive the record only when the route id equals the returned name;
- connections without a route id receive every record whose type matches (they are not an "else" branch).
- If no connection matches the returned name (for example the default template's empty string), the record is dropped silently.
- An exception thrown by the script fails the record (normal error handling of the flow applies).
- Without a script the designer shows a "no condition" indicator and a warning; the default template returns an empty string.
Notes
- To build an "else" branch, return an explicit name for it (for example
"Other") and set that route id on the connection; do not leave a connection without a route id. - The route id is stored on the record object itself. If a downstream component passes the same record on, the route id travels with it and can affect other route-id connections later in the flow.
- The script runs on every record; keep it fast and free of side effects.
Example
Script returns "Large" or "Small":
Http listener → Decision router → (route id Large) Approval flow ; (route id Small) Database writer