A Guide to Conditional Logic in Okta Workflows Automation

In this blog post:

  1. Set up conditional logic
  2. Set up conditional logic for error handling
  3. Stop execution in conditional branches
  4. More conditional logic examples
  5. Related Okta Workflows guides
  6. Okta Workflows resources

This blog post teaches you how to set up conditional logic (if/else) in an Okta Workflows automation.

πŸŽ₯ Attend our online meetup on Tuesday, September 30, 10 AM PT. You will learn more about setting up conditional logic in Okta Workflows.

Okta Workflows Branching functions.
Okta Workflows Branching functions.

Okta Workflows has several if/else cards in the Branching category:

  • Assign If
  • Continue If
  • Lookup
  • If/Else
  • If/ElseIf

Set up conditional logic

Use the Assign If card

The Branching-Assign If card is a simple decision-making card. It checks whether a condition is true or false. Then, it assigns a specific value to a field based on the outcome. Think of it as a basic β€œif-else” statement for setting a single value.

Using the Assign If card.
Using the Assign If card.

How the flow works

  1. The Flow Control-Assign card sets the Expense amount value to 100.
  2. The Branching-Assign If card checks its condition. Is the Expense amount (100) less than or equal to 250?
    • If less than or equal (true), then it sets the Is approved output field to Approved.
    • If greater than (false), then it sets the Is approved output field to Need approval.
  3. The Text-Compose card displays the Is approved value.

The Assign If card only sets a field’s value. It doesn’t support adding extra logic in either the true or false sections. Other cards we cover next allow adding extra logic.

The Assign If card only assigns a value. It doesn’t do other functions or actions. Its sole purpose is to populate a single field based on one condition.

Use the Continue If card

The Branching – Continue If card evaluates a condition. If the condition is true, the flow continues to the next step. If the condition is false, the flow execution stops. So, use this card to stop or continue running a flow based on a condition.

This flow stops if the Expense amount is less than 250. It continues to the next step if the Expense amount is greater than 250.

Using the Continue If card.
Using the Continue If card.

How the flow works

  1. The Assign card sets Expense amount.
  2. The Continue If cards check if the Expense amount is greater than 250.
    • If true (greater than 250), then continue to the next step.
    • If false (less than 250), the flow stops.
  3. The Compose card displays text if the Continue If card evaluates to true.

This execution shows the flow stops at the Continue If card since the condition evaluated to false (100 > 250).

Running a flow with Continue If card.
Running a flow with the Continue If card.

This execution shows the flow continues to the next step since the condition evaluated to true (500 > 250).

Running a flow with Continue If card.
Running a flow with the Continue If card.

Use the Branching-Lookup card

The Branching-Lookup card converts one value to another using a lookup table.

This flow looks up a region and returns its description:

Using the Lookup card.
Using the Lookup card.

How the flow works

  1. The Assign card creates a field with a value.
  2. The Lookup card looks for a result using the value the Assign card passed to it.

This flow execution shows passing EMEA to the Lookup card. The card returns Europe, the Middle East, and Africa.

Running a flow with the Lookup card.
Running a flow with the Lookup card.

This flow execution shows running the Lookup card with an unknown value, which results in the outcome No region found.

Running a flow with the Lookup card.
Running a flow with the Lookup card.

Use the Branching-If/Else card

The Branching-If/Else card evaluates a condition. If it’s true, it runs one set of cards; if it’s false, it runs another.

This flow shows the If/Else card checking if the Expense amount is greater than 500:

Using the If/Else card.
Using the If/Else card.

When you add the If/Else card to a flow, it will prompt you to set a condition. Clicking Save will switch to the view you see above. Click the pencil icon next to Expense amount > 500 to switch back to condition editing.

A flow with the If/Else card.
A flow with the If/Else card.

How the flow works

  1. The Assign card sets an Expense amount.
  2. The If/Else card evaluates whether the Expense amount is greater than 500.
    • If true, it runs the cards in the true branch.
    • If false, it runs the cards in the false branch.
    • The card also has an optional output field named Message. The Message field is set to either the message in the true branch or the false branch.

Running the flow with an input of 100 runs the false branch:

Running a flow with the If/Else card.
Running a flow with the If/Else card.

Running the flow with an input of 575 runs the true branch:

Running a flow with the If/Else card.
Running a flow with the If/Else card.

Use the If/Elseif card

The Branching-If/Elseif card is the most flexible conditional card. The card allows to specify more than one condition to check. The card allows to build this conditional logic:

if (...)
else if (...)
else if (...)
else

The If/Elseif has If and Else branches when you add the card to a flow. Click the + between the branches to add more Else if branches.

Adding the If/Elseif card.
Adding the If/Elseif card.

This flow shows the If/Elseif card with three branches:

The If/Elseif card with three branches.
The If/Elseif card with three branches.

How the flow works

  1. The Assign card sets Expense amount value.
  2. The If/ElseIf card defines three conditions and sets a different messages for each condition.
  3. The last Assign card displays the message from the If/Elseif card output.

Click on + inside a branch to add cards to run when this condition is true. You can also define output for the card (click View Outputs to reveal the outputs).

Cards to run when a condition is true.
Cards to run when a condition is true.

The next three images show running the flow using three inputs.

Flow execution with the first branch evaluating to true.
Flow execution with the first branch evaluating to true.
Flow execution with the second branch evaluating to true.
Flow execution with the second branch evaluating to true.
Flow execution with the third branch evaluating to true.
Flow execution with the third branch evaluating to true.

Set up conditional logic for error handling

Okta Workflows has the Error Handling-If Error card. This card allows to specify alternate steps to handle an error without stopping a flow.

This flow show the If Error card’s Try branch. The Okta-Read User card reads information about a user. But since the ID is invalid, the card will return an error.

Using the If Error card, Try branch.
Using the If Error card, Try branch.

This flow shows the card’s If Error branch. If the steps in the Try branch result in an error, execution will jump into the If Error branch. This allows to handle the error and continue flow execution.

Using the If Error card, If Error branch.
Using the If Error card, If Error branch.

Running the flow where the Read User card fails:

Handling an error and continue flow execution.
Handling an error and continuing flow execution.

Stop execution in conditional branches

Note the difference in behavior when placing the Return card inside a branch.

  • If/Elseif β€” the branch stops, the flow continues.
  • If Error β€” the branch stops, the flow continues.
  • If/Else β€” the branch and the flow stop.

Use the Return card inside a branch

When you use the If/ElseIf or If Error card, each branch is an anonymous helper flow. Just like a helper flow, a Return card returns you to the parent rather than halting.

When you use the Return card inside a branch, the execution stops the branch steps. It exits the branch and will continue to the next card.

The flow below adds the Return card in the Else branch. It also adds another field to the Assign card so you can see the flow steps continue.

The If/Elseif card with a Return card.
The If/Elseif card with a Return card.

The Return card stops the Else branch; but, the execution continues. Since the If/Esleif card stopped, the Message field is not set. Only the Message 2 field is set since it is static.

Running the  If/Elseif card with a Return card.
Running the If/Elseif card with a Return card.

Additionally to the Return card, the Continue If card works the same way when placed inside a branch.

Read more in the Branches section, in the cards’ documentation:

The If/Else and Return cards

If you place a Return (or the Continue If) card in the If/Else card’s branch, the flow execution will stop. This happens because it does not use an anonymous helper flow.

More conditional logic examples

This guide covered the Assign If card earlier. The card evaluates a condition and assigns a value to a field. The card is really just a specialized version of the more generic If/Else card.

This flow with the Assign If card

Using the Assign If card.
Using the Assign If card.

works the same way as this flow with the If/Else card:

Using the If/Else card in the same way as the Assign If card.
Using the If/Else card in the same way as the Assign If card.

In a similar fashion, you can use the If/Else card to show how the Continue If card works:

Using the If/Else card in the same way as the Continue If card.
Using the If/Else card in the same way as the Continue If card.

Okta Workflows resources

πŸš€ New to Okta Workflows? The Getting Started with Okta Workflows page has all the resources to help you get started.

πŸ“Ί Like learning from videos? Watch Okta Workflows videos.

❓Have a question? Ask during community office hours, post on the community forum, or email me.

πŸ™‹πŸ»β€β™€οΈ Want to learn from the community? Join the #okta-workflows channel on the Mac Admins Slack.

πŸ“– Want to learn more about identity automation? Take Workflows training on Okta Learning.

Leave a comment