Getting an individual level

Later in this tutorial series, we're going to need to retrieve a level based on a provided point value — and we're going to need to do this multiple times.

To avoid redundant work, we can create a Function flow. This is a flow that can only be invoked by other flows. It's a way of encapsulating complex logic for reusability.

Step 1: Create a "Function" flow

  1. In the Explorer pane, click Create new.
  2. Select Function.
  3. Type Get level.
  4. Tap the Return key.

Step 2: Configure the "Start" component

  1. Open the Start component.
  2. Create an input argument called point. You'll be able to provide a value for this argument when invoking the Function flow from another flow.

Step 3: Get a level from the database

  1. Add a Select component to the flow.
  2. From the Table dropdown, select levels.
  3. In the Filter tab:
    1. Create a condition that checks if Field: max is greater than Start.arguments.point.
    2. Create a condition that checks if Field: min is less than or equal to parseInt(Start.arguments.point) + 1.

Step 4: Get the ID of the level and its badge

  1. Add a Build Object component to the flow. You can use this component to create arbitrary of objects of key-value pairs.

  2. Configure the component with the following properties:

    Property NameValue
    levelIdSelect.data[0].Id
    badgeIdSelect.data[0].badgeid

Step 5: Return the ID of the level and its badge

  1. Add an End component to the flow.
  2. Add a return value called level.
  3. For the value of the return value, enter Build_Object.result.

This is what the complete flow looks like: