DEV Community

Max Katz for Okta Workflows

Posted on • Originally published at maxkatz.net on

Workflows Tips #13: Six (Awesome) Tips for Using If/Else Logic

In this post:

  • How to use OR in an if-statement
  • Comparisons are type sensitive
  • Don’t nest more than 3 If/Elseif statements
  • Passing in values to be used within the If/Else
  • Creating output for an If/Elseif card
  • How to build a flow with multiple conditions

How to use OR in an if-statement

This tip is from Arek Dreyer. Arek is a Senior Product Engineer at kandji.io, which provides next-generation Apple device management for macOS, iOS, iPadOS, and tvOS. Arek spent over 20 years as an independent trainer, author, and consultant, and in 2021 he joined Kandji. He was super happy to discover the community of admins that love helping each other solve problems in the Okta Workflows space.

You need to create an if-statement for the following conditions:

If device has platform=Mac
If device has platform=iPhone or platform=iPad
If device has platform=Apple TV
Enter fullscreen mode Exit fullscreen mode

Note that the second if-condition has two conditions. The achieve the or condition, use the Branching – If/Elseif card with Else If condition checking if the value is in a list.

Using Else If with OR condition

Using Else If with OR condition

Comparisons are type sensitive

This tip is from AJ Ahrens, Workflows Team Lead at Okta.

When using Branching – If/Elseif card, remember that comparisons are type sensitive. Check you are comparing the same data types. For example, Number comparison of numbers is different than Text comparison of numbers.

The Flow Control – Assign card has input as Numbers. But, in the Branching – If/Else card the compare types are set (by mistake) to Text.

If/Else card comparison with different data types

If/Else card comparison with different data types

When you run the flow you get incorrect result due to incorrect data types:

Incorrect result due to incorrect data types

Incorrect result due to incorrect data types

Go back to If/Else card and change the types to Number for the condition to be evaluated correctly.

Don’t nest more than 3 If/Elseif statemets

This tip is from AJ Ahrens, Workflows Team Lead at Okta.

Don’t nest more than 3 If/Elseif statements. It is difficult to understand how it works and debugging is even more challenging.

Passing in values to be used within the If/Else

This tip is from AJ Ahrens, Workflows Team Lead at Okta.

This one is actually a tip-bug. It will be fixed. For now it’s a good idea to be aware of it and there is a workaround.

When you pass a value into an If/Elseif card as shown below you will get an error.

Passing values from outside If/Elseif

Passing values from outside If/Elseif

Passing values from outside If/Elseif

A solution until this bug is fixed is to use Flow Control – Assign card inside the If/Elseif card to pass in the value as shown below:

Passing values from outside If/Elseif with the help of Assign card

Passing values from outside If/Elseif with the help of Assign card

Passing values from outside If/Elseif with the help of Assign card

Creating output for an If/Elseif card

This tip is from Bryan Barrows, Workflows Builder Advocate at Okta.

It might not be clear how to create an output for the Branching – If/Elseif card. Check out this 30-second video on how to create an output:

How to build a flow with multiple conditions

This tip is from Bryan Barrows, Workflows Builder Advocate at Okta.

Ok, so this is how it works:

  • Use multiple True/False – Compare cards for comparisons
  • Take the restyle from these comparisons and feed them into True/False – And card. You can also use Or, Or (Exclusive), NOT, and XNOR cards
  • From there, feed the true/false value to a Branching – If/Else card

This allows to setup logic for different scenarios where you have a number of conditions and you either need all of them to be true, one of them to be true, none of them, etc.

Multi-condition flow

Multi-condition flow

Two resources to help you learn more:

📌 Try this step-by-step getting started tutorial: Build Your First Automation With Okta Workflows: Notify When User Is Suspended.

📌 All the Workflows resources (docs, tutorial, office hours, templates, office hours and more)

Top comments (0)