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

Jim Coyne
Kilo Patron

Depending on what you are checking, the Switch activity may work for you - http://wiki.servicenow.com/index.php?title=Condition_Activities#Switch


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!!


Fantastic. I discovered there are just many ways to do that. I 'll use switch activity for having it clean! but I can also use multiple if conditions... and connect one to each other to make an if/else/else if.



Thank you both!


Hi,


I can't seem to get this working in my workflow.   The activity result keeps wanting to be 'no' even though my logging shows that it should be returning a different value.


Here's my current If script.


answer = ifScript();


gs.log(answer);




function ifScript() {


  gs.log('CEC ' + current.u_cec_hot);


  gs.log('Interviewer ' + current.u_interviewer_noted);


  gs.log('OPS ' + current.u_ops_hot);


  gs.log('Contact ' + current.u_contact_requested);


  if (current.u_cec_hot == true) {


  gs.log('CEC script true');


  return 'cec';


  }


  else if (current.u_interviewer_noted == true) {


  gs.log('Int script true');


  return 'interviewer_noted';


  }


  else if (current.u_ops_hot == true) {


  gs.log('Ops script true');


  return 'ops';


  }



  else if (current.u_contact_requested == true) {


  gs.log('Contact script true');


  return 'contact_requested';


  }




}


My log for answer shows 'cec' is being returned, but in my If condition, the activity.result == 'cec' path is not being followed.   Any ideas?