This guide presents how to reduce a list to a single value using the Workflows Reduce card.
- Okta Workflows
What is the Reduce card?
The Reduce card takes a list of values and reduces them to a single value.
For example, there is a list of text values:
- Milk
- Bread
- Butter
- Eggs
- Cheese
It is desired to obtain a single text value consisting of all the values from the list:
> Groceries:
* Milk
* Bread
* Butter
* Eggs
* Cheese
It is necessary to reduce the list to a single value.
The solution has two flows:
- The main flow that creates the list and calls the Reduce card
- A helper flow that concatenates each text
Creating a list and calling the Reduce card
The main flow creates the list and calls the Reduce card:
- The List – Construct card creates the list.
- The List – Reduce card takes the list and runs the Helper helper flow on each item.
- memo has an initial value of > Groceries.
- Values from the list will be added to the initial value.
- Item is each item value from the list
- In the output section, the item holds the reduced value after all the items are processed.
- The Text – Compose card displays the reduced value.
NOTE: memo field type (Text) needs to match the card’s output item field type (Text).
Helper flow to process (reduce) each list item
This is the helper flow:
The helper flow runs for each item in the list.
First run
On the first run, the memo value is:
> Groceries
and
* Milk
is appended to it.
The helper flow returns:
> Groceries
* Milk
Second run
On the second run, the memo value is:
> Groceries
* Milk
and
* Bread
is appended to it.
The helper flow returns
> Groceries
* Milk
* Break
Third run
On the third run, the memo value is:
> Groceries
* Milk
* Break
and
* Butter
is appended to it.
The helper flow returns:
> Groceries
* Milk
* Break
* Butter
Fourth run
On the fourth run, the memo value is:
> Groceries
* Milk
* Break
* Butter
and
* Eggs
is appended to it.
The helper flow returns:
> Groceries
* Milk
* Break
* Butter
* Eggs
Fifth run
On the fifth run, the memo value is:
> Groceries
* Milk
* Break
* Butter
* Eggs
and
* Cheese
is appended to it.
The helper flow returns:
> Groceries
* Milk
* Break
* Butter
* Eggs
* Cheese
Since cheese is the last item, the Reduce card completes processing.
The last helper flow run:
This is the final result. A list of items is reduced to a single text value
> Groceries
* Milk
* Break
* Butter
* Eggs
* Cheese
