Writing a more complex workflow - connector configuration

In the section Writing a simple workflow, we created a workflow which performed the following operations:

  • Prompts the user to select a CSV File

  • Opens a CSV File

We will now use our knowledge about connectors to create a more complex workflow. This workflow will not only select and open a CSV File, but will also:

  • Perform a calculation using a Python expression component

  • Write the value calculated by the expression to the CSV

To create the workflow:

  1. Initialise a blank workflow by opening the Workflow Editor or clicking New.

  2. Add a Python Expression component to the workflow by either:

    • Searching for "Python Expression" in the Toolbox Filter.

    • Navigating to Script Engine > Python Expression in the Toolbox.

  3. Add an input connector to the component by right-clicking the component and selecting Add Input connector.

  4. Click on the input connector to configure it. To configure the connector:

    1. Set the connector’s type to Integer.

    2. Select the Associate an attribute to this connector checkbox. Remember, the connector is a vessel which transports data. Data can contain multiple attributes. Each connector is assigned one attribute to carry.

    3. Set Attribute name to Input_1. This is important because it will be referenced within the Python Expression.

    4. Ignore the Value source drop-down field in this example. This only matters if there is incoming data.

    5. Select the Use this value as a default checkbox and set its value to 15.

  5. Create an output connector by right-clicking the component and selecting Add output connector.

  6. Configure the output connector by completing the following steps:

    1. Set its type to Integer.

    2. Select the Associate an attribute to this connector checkbox.

    3. Set its attribute name to Output_1. This is important because it will be referenced in the Python Expression.

    4. Set its Value source to Match by name.

  7. Click on the Python Expression component to open up the panel on the right. Within that panel will be a script field.

  8. In the script field, write the following equation:

    Output_1 = Input_1 + 2

  9. Add a Data Query component to the workflow by searching for "Data Query" in the Toolbox Filter (see step 2).

    Disconnect the Data Query component from the workflow, as the workflow should run this component at the same time as the Python Expression component and not before or after. Connect the top of the component to the Start component. Your workflow should look like this:

  10. Click the middle of the Data Query component to configure it. To configure the component:

    1. In the Data item type drop-down, navigate to File > Spreadsheet > CSV Files.

    2. Enable manual selection of the file via a file browser by selecting the Open a file browser to allow manual selection radio button.

  11. Click on the Result connector to configure it. To configure the connector, set the type to CSV Files.

  12. Add a Data > Spreadsheet Data component to the workflow.

  13. Add an input connector to the Spreadsheet Data component.

  14. Click on the input connector to open the configuration panel. Configure the input connector by completing the following steps:

    1. Set the type to Integer.

    2. Enable the Associate an attribute with the connector checkbox.

    3. Set the attribute name to Input_1.

    4. Set the value source to Match by type.

  15. Join the output of the Python Expression component to the newly created input.

  16. Add another input connector to the Spreadsheet Data component.

  17. To configure the input connector:

    1. Set the type to Spreadsheet - CSV File.

    2. Select the Associate an attribute to this connector checkbox.

    3. Set the value source to Match by type.

  18. Join the output of the Data Query component with the input you have just created.

  19. Click on the Spreadsheet Data component to open the configuration panel. Configure the component by completing the following steps:

    1. Set the spreadsheet file to $(Input_2). Note that you are referring to a variable set in a previous component.

    2. Select the Write radio button.

    3. Set From attribute to $(Input_1).

    4. Set To cell reference to H2. This means you are writing the variable Input_1 to cell H2.

  20. Add an Application Commands > Workbench > CSV Editor component. The final workflow should look like this:

  21. Run the workflow. You should be able to:

    1. Calculate a value from the Python Expression component.
    2. Write the value to a CSV.
    3. Open the CSV.

Next topic: Getting Started - Building on Key Concepts - How components work