1. Home
  2. Flow Hello World in XML

Flow Hello World in XML

◷ Reading Time: 4 minutes

Modeling a Flow

The main container in Flow looks as follows:

<Flow name="FlowName" version="1.0.0.0">
  <Declaration>
    <!-- section to define parameters: Variables or Types -->
  </Declaration>
 
  <Nodes>
    <!-- Nodes and Transitions come in this section -->
  </Nodes>

</Flow>

where you can replace your name in the name setting of the model. In the Declaration section, you can define the Parameter.

Mandatory Nodes

All Flows must have at least two Nodes:

  1. Start node
  2. End node

And a Transition that connects the Nodes to each other:

<Flow name="FlowName" version="1.0.0.0">
 
  <Nodes>
   <Start name="startNode">
      <Transition name="tr1" to="endNode"/>
   </Start>
 
   <End name="endNode" />
  </Nodes>
 
</Flow>

In this example, we simply defined a Flow that has two nodes and one transition that connects the Start node to the End node. Please note that the End Node cannot have any Transitions.

Also, it is important that in a Flow all names must be unique (i.e., Nodes, Transitions, etc.).

Adding an Activity

The simplest way to add a task to be achieved in a Flow is using an Activity node.

<Flow name="Flow1" version="1.0.0.0">
  <Nodes>
    <Start name="nodeStart">
      <Transition name="tr0" to="Activity1" />
    </Start>
 
    <Activity name="Activity1">
      <Transition name="tr1" to="nodeEnd" />
    </Activity>
 
    <End name="nodeEnd" />
  </Nodes>
</Flow>

This becomes a flow, similar to the following:

An activity in flow can either:

  1. Execute an expression parameter of an Activity node
  2. Be linked to other models:
    1. Procedural Activity node
    2. Validation Validator node
    3. Decision Table Decision Table node
    4. Natural Language Natural Language node
    5. Decision Requirement Diagram Drd node
    6. Information Requirement Diagram IRD node
    7. Sub-Flow CallFlow

Adding Hello World Action

In this example, we link the activity to a procedural logic. The simplest way of referencing an action to an Activity Node is referencing the Node to a procedure.

Let’s say we have the following procedure saved as HelloWorld.xml

<Procedure name="hello">
  <Declaration>
    <Using path="System.Console"/>
  </Declaration>
 
  <CallMethod method='Console.WriteLine("From Flow: hello world!")'/>
</Procedure>

Then using CallProc, we can reference the procedure to the node. Make sure that the Flow and Procedure models are both located next to each other.

Complete Flow Model

<Flow name="FlowRuleFlow" version="1.0.0.0">
  <Nodes>
    <Start name="nodeStart">
      <Transition name="tr0" to="Activity1" />
    </Start>
 
    <Activity name="Activity1">
      <CallProc contextMode="New" resultCopyMode="None">
        <ProcSource uri="HelloWorld.xml" />
      </CallProc>
      <Transition name="tr1" to="nodeEnd" />
    </Activity>
 
    <End name="nodeEnd" />
  </Nodes>
</Flow>

Executing a Flow

Executing the flow is easy. There are just a couple of steps that need to be followed.

  1. Loading a Runtime engine
  2. Calling run method of engine
private void RunHelloWorld()
{
    //TODO: insert your path to the flow xml model source below, and replace YOUR_PATH_GOES_HERE with your path to your xml model source
    string flowPath=YOUR_PATH_GOES_HERE; 
    var engine = RuntimeEngine.FromXml(File.OpenRead(flowPath));
 
    // execute!
    engine.Run();
}
Updated on October 7, 2022

Was this article helpful?