Okta Workflows How-To: Reduce a List to a single value

Three examples using the List-Reduce card

About the Author

Max Katz

Staff Developer Advocate, Okta Workflows

Max Katz is a Staff Developer Advocate for Okta Workflows. Max loves the no-code automation space and creating educational content. Before Okta, Max led the North America Developer Advocacy team at IBM. Before IBM, Max led developer advocacy for a cloud-based mobile app platform, Appery, helping it grow from zero to over 400,000 developers. Max regularly writes on his http://maxkatz.net blog. 

13 December 2022 Time to read: ~

A person is seated at a wooden desk in a casual workspace

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.

A vertical list construct interface with five numbered items. 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.

Workflow configuring a list reduce operation. A flow with a List-Reduce card

Before creating the helper flow, this is how the helper flow works (each bullet point is the 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:

Workflow displaying a helper flow named "Helper_Reduce_Sum". 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.

Workflow interface with two connected panels labeled Construct and Reduce. 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
A List Reduce configuration panel in a visual workflow editor. Setting result type

You are ready to run the flow.

This is the main flow execution:

Workflow with two connected modules labeled Construct and Reduce. 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
Workflow interface with three connected panels labeled Helper Flow, Add, and Return. 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
Workflow builder interface with three connected panels labeled Helper Flow, Add, and Return. 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
A three-step digital workflow interface for adding numbers. 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
Workflow interface with three connected panels. 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
Workflow interface with three connected panels. 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:

Workflow with two connected panels labeled Construct and Reduce. A flow to find the largest number

This is the helper flow:

Workflow showing connected blocks in a flow diagram 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 as the memo value for the next run.

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

The final result where the biggest number is 60.

Workflow displaying two connected modules labeled Construct and Reduce. 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:

Workflow builder interface showing multiple connected panels. Create single message flow

This is the helper flow:

Workflow builder interface showing a helper flow configuration. 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.

Workflow interface with multiple connected panels. Helper flow

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

Workflow interface with multiple panels labeled Assign, Construct, Reduce, and Compose. Using List – Reduce card to build a message

What you learned

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 the Walkthrough

See how to use the List-Reduce card in this video demonstration.

Vidyard 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. 

About the Author

Max Katz

Staff Developer Advocate, Okta Workflows

Max Katz is a Staff Developer Advocate for Okta Workflows. Max loves the no-code automation space and creating educational content. Before Okta, Max led the North America Developer Advocacy team at IBM. Before IBM, Max led developer advocacy for a cloud-based mobile app platform, Appery, helping it grow from zero to over 400,000 developers. Max regularly writes on his http://maxkatz.net blog. 

Continue your Identity journey