The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to make an If/else/else if in the workflow editor

jesusemelendezm
Mega Guru

Hi ServiceNow people!

 

I want to have a condition for something like this:

 

  • if statement
  • if...else statement
  • if...elseif....else statement
1 ACCEPTED SOLUTION

bgworld
Giga Expert

Hi Jesus E. Melendez M.,



As suggested by Jim you can use the switch statement.



Otherwise to make it more of geeky you can modify the condition scripts of if conditions.



1. Checkout any workflow


2. In any of the if activity, right click on activity and select add condition, you will see new form something like this.


ifcondition.PNG


Activity.result is the value you return from if condition or if script.


You can use script and return as many values as you want and create many flows as shown below.


additional_flows.png




Hope it Helps!!


View solution in original post

7 REPLIES 7

Just ran across a lab that walks through doing exactly what I was needing to do.


Here's the link for anyone looking to accomplish this


Mini-Lab: Workflows - Playing With the If Activity


What I've discovered about evaluating the activity.result value in the IF workflow activity, is that activity expects the value of activity.result to be only 'yes' or 'no' and nothing else. If you try to set activity.result to something other than 'yes', for example, 'contact_requested', the value of activity.result will be 'no'.



Which is odd because the Wiki uses the language "Possible result values are:" and then lists 'yes' and 'no', but the wording of "possible" implies that activity.result can be set to something other than 'yes' or 'no'.



To get around the activity.result limitation, you can script any other evaluation in the condition variables of the IF activity. The excellent mini-lab written by Steven Bell outlines this technique. The Conditions in his lab evaluate the value of workflow.scratchpad values and not the activity.result value.



Michael


mansing
Giga Contributor

This method did not work for me, in condition it only accepts activity.results == 'yest' and activity.results == 'no'.



I am trying to add four conditions Windows, Linux, Other OS and Incorrect input. I have script written where I am returning value as return 'windows'/'linux'/etc.. but that does not work.



Any way to sort this issue?