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

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: What are the differences between three List functions: For Each, Map, and Reduce? 

Getting started

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 doesn’t 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’s look at every function with an example. 

List – For Each

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

You have a list of users and need to process each user. For example, de-provision each user, cancel their subscription, update their profile, or send them an email. 

The For Each card doesn’t return output. 

Here is an example. 

workflows 3listactions foreach mainUsing For Each card, main flow

In the screenshot above: 

  1. The Assign card sets the group ID
  2. List Group Members card lists all users in a group
  3. 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:

workflows 3listactions foreach helperFor Each card 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, you retrieve specific fields from the User object. 
  3. Next, you process each user. For example, de-provision each user, cancel their subscription, update their profile, or send them an email. In this short example, you are displaying the values using the Compose card

In summary, the For Each card processes each item in a list with a helper flow but doesn’t return a value back to the main flow. 

Learn how to use the List – For Each card

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

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. 

You have a list of users and need a new list where each user is listed as lastname.firstname

workflows 3listactions map mainUsing Map card, main flow

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 doesn’t return a value
  4. The Assign card is used to display the returned list

This is the helper flow: 

workflows 3listactions map helperUsing the Map card, 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, you can retrieve specific fields from the User object. In this flow, you retrieve the ID, First Name, and Last Name
  3. Using the Concatenate card, you 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: 

workflows 3listactions map helper historyUsing the Map card, helper flow run

In summary, the Map card 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.

Learn how to use the List – Map card

How to Iterate Over Items and Create a New List (or How to Use the List – Map Card)

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.

workflows 3listaction reduce mainUsing the Reduce card, main flow

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

The is the helper flow: 

workflwos 3listaction reduce helperUsing the Reduce card, 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, you can retrieve specific fields from the User object. In this flow, you retrieve the Email, First Name, and Last Name
  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 ([email protected])

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

People list: 

Max Katz ([email protected])
Stella Green ([email protected])

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

People list: 

Max Katz ([email protected])
Stella Green ([email protected])
Olivia Green ([email protected])

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

People list: 

Max Katz ([email protected])
Stella Green ([email protected])
Olivia Green ([email protected])
Alicia Web ([email protected])

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

People list: 

Max Katz ([email protected])
Stella Green ([email protected])
Olivia Green ([email protected])
Alicia Web ([email protected])
Jacqueline Miles ([email protected])

 

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

workflows 3listaction reduce reduce cardList – 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.

Learn how to use the List – Reduce card

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

Video

Watch a short video about these flows.

 

 

Summary

In this blog post, you learned how to use three List actions: 

  • For Each – processes each item in a list with a helper flow. Helper flow doesn’t 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

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