Okta Workflows How-To: Reduce a List to a Single Value, 3 Examples Using List-Reduce Card

Okta Workflows is a no-code platform for automating identity processes. 

This blog post is based on a question asked during office hours or the #okta-workflows channel in MacAdmins Slack: How to use the List-Reduce card in Workflows? 

Getting started

The List-Reduce card takes a list of values and reduces the list to a single value.

Here are a number of examples where you can use the List-Reduce card to reduce a list of values to a single value:

  • A list of numbers – sum all the numbers
  • A list of numbers – find the largest (or smallest) number
  • A list of messages (text) – create a single message containing all the messages from a list

A good way to understand how this card works is to look at an example to return the sum of all the numbers in a list.

At the end of this blog post, you can download the examples.

Sum all numbers in a list

Starting with a list of numbers, you want to sum up all the numbers.

workflows_howto_reduce_list_numbers.png (492×1056)A list with numbers

In order to sum up the numbers, you are going to use the List-Reduce card that requires a helper flow.

workflows_howto_reduce_helper_notset_2.png (1026×1052)A flow with a List-Reduce card

Before creating the helper flow, this is how the helper flow works (each bullet point is helper flow running once):

  • 0 (memo, initial value) + 1 = 1
  • 1 + 2 = 3
  • 3 + 3 = 6
  • 6 + 4 = 10
  • 10 + 5 = 15

The List-Reduce card walks through the list number-by-number, at each step adding the current number to the sum from the previous step.

The result of this flow is 15.

The list of numbers was reduced to a single value of 15.

Now let’s build the helper flow so you can set it in the List-Reduce card.

How to Setup a Workflows Helper Flow (With For-Each and Streaming Cards)

This is how the helper flow looks:

workflows_howto_reduce_helperflow.png (1630×916)Reduce helper flow

The first card, On Demand-Helper Flow, makes this flow a helper flow. It has two inputs:

  • current number – the current number from the list
  • memo – holds the initial value when the flow runs for the first time and then stores and passes in the sum after each run

The second card, Number-Add, adds two numbers. It adds the current number from the list with memo – which is the previous sum.

The last card, Flow Control-Return, returns the current sum. This sum value is passed back into the helper flow using the memo field.

The helper flow continues to run until all the list numbers are processed.

Now that the helper flow is completed, you can set it on the List-Reduce card. After choosing a helper flow, set the current number field value. Click the arrow pointing down and select item.

workflows_howto_reduce_helperflow_set.png (1034×1064)A flow with a List-Reduce card

Two things to remember:

  • Set the memo field to type Number. It holds the initial and intermediate sum values when the helper flow runs. Its type should match the type you expect as the final result
  • Set the item (result) to type Number

workflows_howto_reduce_number_type_2.png (508×1006)Setting result type

You are ready to run the flow.

This is the main flow execution:

workflows_howto_reduce_run_mainflow.png (1052×888)Running the main flow

A list of [1,2,3,4,5] is passed to the List-Reduce card. The final sum is 15 (item field).

Now let’s look at the helper flow executions.

In the first run, the flow is adding:

1 + 0 = 1

  • 1 – current number from the list
  • 0 – memo

workflows_howto_reduce_run1.png (1630×578)First run

In the second run, the flow is adding:

2 + 1 = 3

  • 2 – current number from the list
  • 1 – sum from the previous run, passed with memo field

workflows_howto_reduce_run2.png (1630×574)Second run

The third flow run:

3 + 3 = 6

  • 3 – current number from the list
  • 3 – sum from the previous run, passed with memo field

workflows_howto_reduce_run3.png (1632×578)Third run

In the fourth flow run:

4 + 6 = 10

  • 4 – current number from the list
  • 6 – sum from the previous run, passed with memo field

workflows_howto_reduce_run4.png (1638×574)Fourth run

In the fifth and final run:

5 + 10 = 15

  • 5 – current number from the list
  • 10 – sum from the previous run, passed with memo field

workflows_howto_reduce_run5.png (1634×576)Fifth run

This example showed you how to sum up a list of numbers (or, reduce a list of numbers to a single value).

Let’s look at more examples that use the List-Reduce card.

Find the largest number in a list of numbers

In this example, you have a number list and want to find the largest number in the list. This is the main flow:

workflows_howto_reduce_largest_main.png (1018×1142)A flow to find the largest number

This is the helper flow:

workflows_howto_reduce_largest_helper_flow.png (1642×1020)Finding the largest number – helper flow

In this flow, the Branching-Assign If card is used to compare two numbers, and the bigger number is returned back as the memo value for the next run.

Then the new current number is compared against the current biggest number (memo). The bigger of them is returned. This continues until all the numbers are processed.

The final result where the biggest number is 60.

workflowd_howto_reduce_largest_run.png (1040×996)Finding the largest number

Let’s look at another example.

Creating a single message from multiple messages

This example creates a single message from multiple messages. For example, there is a list of users who were activated. You need to create one message that includes all the messages/users.

This is the main flow:

workflows_howto_reduce_message_main.png (2488×996)Create single message flow

This is the helper flow:

workflows_howto_reduce_message_helper_flow.png (2028×910)A helper flow to create a single message from multiple messages

The following screenshot shows the helper flow 2nd execution. It shows how the message is built.

workflows_howto_reduce_message_helper_flow_run2.png (1662×1082)Helper flow

And, this is the main flow execution showing the final message:

workflows_howto_reduce_message_main_run.png (2122×1080)Using List – Reduce card to build a message

In this blog post you learned how to use the List-Reduce card using three examples:

  • A list of numbers – sum all the numbers
  • A list of numbers – find the largest (or smallest) number
  • A list of messages (text) – creating a single message from multiple messages

Try these examples:

  1. Download the flows file
  2. Uncompress the file (you should get reduce.folder file)
  3. Import reduce.folder into Workflows

Watch examples video:

Get your Workflows questions answered

Do you have a question about Okta Workflows? Not sure how to build a flow? Join the weekly community office hours to get help. 

Tags

Workflows