<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
Learn the Differences Between Three Workflows List Functions: For Each, Map, and Reduce
Workflows
Okta Classic Engine
Okta Identity Engine
Overview

This article describes the difference between three Workflows list functions:

  • For Each
  • Map
  • Reduce
Applies To
  • Okta Workflows
Solution

The List function has three cards to iterate over a list:

  • For Each – processes each item in a list with a helper flow. Helper flow does not return a value
  • Map – processes each item in a list with a helper flow. Creates a new list with modified items. A new list is returned to the main flow
  • Reduce – process each item in a list with a helper flow. Reduces the list to a single value that is returned to the main flow

Let us look at every function with an example. 

  1. List – For Each

The For Each card processes each item in the list with a helper flow. 

If there is a list of users and need to process each user. For example, de-provision each user, cancel their subscription, update their profile, or email them. 

The For Each card does not return output. 

Here is an example:

For Each card

In the screenshot above: 

  1. The Assign card sets the group ID
  2. List Group Members card lists all users in a group
  3. The For Each card calls a helper flow for each user in a group. The User object is passed to the helper flow

This is the helper flow:

Helper Flow

In the helper flow: 

  1. The Helper Flow card defines the flow input. In this example, it is the User object
  2. Using the Get Multiple card, specific fields are retrieved from the User object.
  3. Next, process each user. For example, de-provision each user, cancel their subscription, update their profile, or email them. In this short example, values are displayed using the Compose card.

In summary, the For Each card processes each item in a list with a helper flow but does not return a value to the main flow. 

  1. List – Map

The Map card processes each item in the list with a helper flow. For each item in the list, the Map card adds a new value to a new list. The new list is returned to the main flow. 

If there is a list of users and a need for a new list where each user is listed as lastname.firstname

Map Card

In the screenshot above: 

  1. The Assign card sets the group ID.
  2. List Group Members card lists all users in a group.
  3. Map card calls a helper flow for each user in a group. The User object is passed to the helper flow
    • The Map card returns a list (Last.First List). This is different from the For Each card that does not return a value.
  4. The Assign card is used to display the returned list.

This is the helper flow: 

Helper Flow

In the helper flow: 

  1. The Helper Flow card defines the flow input. In this example, it is the User object.
  2. Using the Get Multiple card, specific fields from the User object can be retrieved. In this flow, the Email, First Name, and Last Name are retrieved.
  3. Using the Concatenate card, create lastname.firstname name format for each user in the list.
  4. Each new name (lastname.firstname) is returned to the main flow. This puts the new name into a list.

This screenshot shows one helper flow run: 

Helper flow

In summary, the Map card processes each item in a list with a helper flow, creates a new list with modified items, and returns a new list to the main flow.

  1. List – Reduce

The Reduce card processes each item in the list with a helper flow. The card reduces the list to a single value that is returned to the main flow.

Reduce card

In the screenshot above: 

  1. The Assign card sets the group ID. It also sets a text variable Memo.
  2. List Group Members card lists all users in a group.

This is the helper flow: 

Helper flow

In the helper flow: 

  1. The Helper Flow card defines the flow input. In this example, it is the User object and the required memo variable
  2. Using the Get Multiple card, specific fields from the User object can be retrieved. In this flow, the Email, First Name, and Last Name are retrieved.
  3. The Compose card adds new user information to the previous message.
  4. The Return card returns the newly created message that is then passed again to the helper flow (until all users are processed).

On the 1st run, memo is set to People list:

The Return card returns: 

People list: Max Katz (max.katz@okta.com)

On the 2nd run, memo is set to the above message and the Return card returns: 

People list: Max Katz (max.katz@okta.com)Stella Green (stella.green@atko.email)

On the 3rd run, memo is set to the above message and the Return card returns: 

People list: Max Katz (max.katz@okta.com)Stella Green (stella.green@atko.email)Olivia Green (olivia.green@atko.email)

On the 4th run, memo is set to the above message and the Return card returns: 

People list: Max Katz (max.katz@okta.com)Stella Green (stella.green@atko.email)Olivia Green (olivia.green@atko.email)Alicia Web (alicia4@atko.email)

And, on the 5th run, memo is set to the above message and the Return card returns: 

People list: Max Katz (max.katz@okta.com)Stella Green (stella.green@atko.email)Olivia Green (olivia.green@atko.email)Alicia Web (alicia4@atko.email)Jacqueline Miles (jacqueline@atko.email)

 

Now that the Reduce card has processed all the items, it reduced the list to a single item (the combined message), and that item is returned to the Message property.

Reduce card

In summary, the Reduce card processes each item in a list with a helper flow. The card reduces the list to a single value that is returned to the main flow.
  1. Video

Watch a short video about these flows.

 

Related References

Loading
Learn the Differences Between Three Workflows List Functions: For Each, Map, and Reduce