O365 Switch Action - What is it good for?

  • 22 April 2015
  • 3 replies
  • 17 views

Badge +6

Welcoming Switch to the O365 action family. Another logic action has been added with the latest release of Nintex Workflow for O365. The Switch action. I am sure many of you have used it on-prem in the past, but for those who are new to the Switch action, let me explain what it is and why you should use it.

 

What is it?

The Switch value is a logic action that allows you to evaluate the value of a workflow variable and perform business logic that is specific to the value of the variable. It looks like a Parallel Block action but only one branch will be processed, rather than all of them.

 

SwitchAction.jpg

 

What is it good for?

So, why would you use the Switch Action, you ask? You can already evaluate workflow variables and item properties with other actions like the Conditional Branch action. Well, let me give you three good reasons why to use the Switch action.

 

Flatten your workflow design

Sometimes, when you evaluate a workflow variable, you might get more than 2 outcomes. Using the Conditional Branch action, the workflow design can quickly become very illogical and cumbersome. Imagine you have a workflow variable called "varDepartment" and the outcomes can be IT, Finance, HR, Sales or PMO.

 

Using the Conditional Branching action, you will end up with a workflow design like illustrated below.

ConditionalBranching.jpg

 

Now, with a Switch action you will end up with a design like this.

SwitchAction.jpg

 

Makes it easier to read, faster to design, looks more logical and instead of configuring 5 different Conditional Action branch, you only configure one Switch action.

 

Replacement for State Machine

Working with the Switch and the Loop N Times or Loop with Condition action, you can mimic a state machine. I am going to leverage an article, published on one of our partner's (Habanero Consulting) blog. You can read more about the advantages/disadvantages of using a Switch action and Loop action vs. a state machine here.

 

Restarting Workflows

For those of you who work with state machines on a regular basis and also face the problem of restarting workflows at a certain process stage, you will appreciate the mix of state machines and the Switch action. Again, I am not reinventing the wheel here, but rather point you to an article here on Nintex Connect. You can read more about restarting workflows via a Switch action here.

 

Great, but how do I use it?

I am glad you asked. The action is very simple to use.

  • Drag & Drop it onto the canvas
  • Double click to open the configuration screen
    SwitchConfig.jpg
  1. The first step is to specify the item property/workflow variable/workflow context variable that needs to be evaluated
  2. Next, the various expected values need to be configured. For each possible variable value, you will have to add an entry
  3. In the "Other Options" you can include a branch for unexpected values. It will be labelled "Other". Also, you can choose to log the value of the variable when the "Other" branch runs. You might wish to do so to monitor values you have missed and extend your switch logic over time. It can also be used to simply bypass the Switch logic if no value matches. In this case you should select the other branch but not include any actions in that branch. Then the workflow will behave the same way as on-prem. It will also allow the value of the Switch variable to be reported so one can see what has happened, but the workflow will still continue and complete.

 

Following the configuration steps above and utilizing our earlier "Department" example, the configured action should look like the below.

ConfigSwitch.jpg

 

One important thing to know when working with the O365 Switch action, is when the other option is not selected and there is not a valid value in the Switch variable. In on-prem the workflow simply skips the whole Switch construct and carries on with the next action after it. In O365 the workflow will suspend. Why did we implement it that way? It is safer in that if an unintended value comes through and then the workflow will not do what is expected, it will not appear as if it has completed successfully but with possibly unintended results.

 

I hope this gave you an idea of how and when to use the Switch action in Office 365 and happy nintexing!


3 replies

Badge +9

Can you believe it, I was working on a workaround yesterday ;-)

Badge +6

almost good timing

Userlevel 4
Badge +6

Thanks for this Patrick, especially the Switch + Loop alternative to State Machines

Reply