Subflow Element

 

  • Subflow Element

        • The use case for Subflows

    Subflow Element



    There are two main use cases for Subflows:

    1. To reduce the complexity of the master flow.
    2. To create reusable flows that can be called from many other flows.

    Creating a Subflow is no different from a normal flow.

    Naming Subflows

    It is a good idea to add "-subflow" to the name to indicate it is a Subflow.

    It is not required but some way of identifying that it is a Subflow is recommended.



    Passing Variables

    You can pass variables in and out of the Subflow (input/output).

    Inputs - receive the variables from the master flow eg recordId for the current record.

    Outputs - to return variables to the master flow after the Subflow has finished running eg the result of a calculation or transaction in the Subflow. If you are just using a subflow to break up the complexity of the master flow, you may not need to return any variables.



    Master Flow

    In this example we have created a master flow with three subflows:

    Note: There is no parameter passing in this example, we will cover that in a later exercise when we actually have something to pass between flows.




    The Screen for the master flow has three radio buttons to select the subflow we want to run next:


    The configuration of the radio buttons:


    Simply run the subflow:


    When we run the master flow in debug mode and select subflow1:


    The subflow1 is run:




  • Exercise: Create a Flow with a Subflow

Build a Flow with a Subflow


Using Subflows is very useful when your flow starts to get very complex or when you create a subflow that needs to be re-used from many flows.

In this exercise, we create a very simple main flow that calls three subflows.

The first thing you need to do is create the subflows. Once they are created, you can create the main flow.

Create the Subflows first

Create a new Screenflow and add a screen component.

Add a Display Text component with a message like this:



Save the subflow:



Do the same for Subflow 2 and Subflow 3.

(hint - you can use save as to make a copy of the flow and make the changes)


Create the Master Flow


Next, create another new Screen Flow for our master flow and add a screen component.

In that screen component, add a Radio Buttons component:



Click in the Select Choices fields and Add New choices for the three subflows:



Do the same for Choice 2 and choice 3.



Add a decision element to your main flow and configure the decisions as follows:



Add another outcome (click the + button) if sub2 is chosen:



Add another outcome (click the + button) if sub3 is chosen:



The final step is to add the link to the subflows:



Add an element below sub1 and select Subflow:



Select your subflow from the list of available flows and give it a label and description:

(note: If you don't see your new subflows listed you may have forgotten to save AND activate them)




Do the same for Sub2 and sub3:



Save your main flow and activate it:



Run your main flow, select one of the radio buttons and see what happens:




If all goes well, the subflow you selected will display it's message.



Click the Previous button and check that the other two options work.



Passing variables between flows and subflows

If you need to pass variables between the main and subflow, remember this:

From the main flow, you need to make your variable available for output and in your subflow you need to make it available for input.

Think of it like this - the variable passes out of the main flow and into the subflow.



No comments: