<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
How to Reduce a List to a Single Value - 3 Examples of Using the List-Reduce Card
Workflows
Okta Classic Engine
Okta Identity Engine
Overview

This article describes how to use the List-Reduce card using three examples.

Applies To
  • Okta Workflows
Solution

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

Here are a number of examples where the List-Reduce card can be used 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 article, download the examples.

 

Sum all numbers in a list

Starting with a list of numbers, sum them all.

workflows_howto_reduce_list_numbers  

To sum up the numbers, use the List-Reduce card that requires a helper flow.

workflows_howto_reduce_helper_notset_2

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 us build the helper flow that can be set in the List-Reduce card.

This is how the helper flow looks:

workflows_howto_reduce_helperflow

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 the 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, 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 an item.

workflows_howto_reduce_helperflow_set

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 expected as the final result.
  • Set the item (result) to type Number.

workflows_howto_reduce_number_type_2

Everything is ready to run the flow now.

This is the main flow execution:

workflows_howto_reduce_run_mainflow

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

Now, let us 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

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

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

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

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

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

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

Find the largest number in a list of numbers

In this example, there is a number list, and it is desired to find the largest number in the list.

This is the main flow:

workflows_howto_reduce_largest_main

This is the helper flow:

workflows_howto_reduce_largest_helper_flow

In this flow, the Branching-Assign If card compares two numbers and returns the larger as the memo value for the next run.

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

The final result was the largest, 60.

workflowd_howto_reduce_largest_run

Let us 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. Create one message that includes all the messages/users.

This is the main flow:

workflows_howto_reduce_message_main

This is the helper flow:

workflows_howto_reduce_message_helper_flow

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

workflows_howto_reduce_message_helper_flow_run2

This is the main flow execution showing the final message:

workflows_howto_reduce_message_main_run

To sum up, this article covered 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 (get the reduce.folder file).
  3. Import reduce.folder into Workflows.

For example, watch the following video:

Related References

 

 
 
 
Loading
How to Reduce a List to a Single Value - 3 Examples of Using the List-Reduce Card