IF Condition in workflow always returns yes

Christopher Dan
Kilo Contributor

I am try to write a IF condition advanced script that will be yes if some locations but no if it is the rest. This will allow me to assign it to the correct assignment group in the workflow. The location variable is a reference field so im not sure if that my issue or not. Please tell me why my script keeps returning yes every time. See script below.

function ifScript() {

  if (current.variables.cmn_location != 'Olofstrom' || current.variables.cmn_location != 'Bielsko-Biala' || current.variables.cmn_location != 'Gothenburg' || current.variables.cmn_location != 'Forsheda')

  return 'yes';

  else

  return 'no';

17 REPLIES 17

Victor,



That was not working properly, so I figured a script would be better.


As Pradeep suggested pasting your code or condition builder examples would help.


Hi Chris,



I feel that above script always return Yes. Suppose if location is 'Olofstrom' then it looks for other condition(like location is not equal to   'Bielsko-Biala') and returns yes because of OR condition and if your location is something else then also it returns Yes. So above condition returns Yes everytime. I would like to know your requirement, may be you are missing to put AND conition instead of OR like


current.variables.cmn_location.getDisplayValue() != 'Olofstrom' && current.variables.cmn_location.getDisplayValue() != 'Bielsko-Biala' && current.variables.cmn_location.getDisplayValue() != 'Gothenburg' && current.variables.cmn_location != 'Forsheda'



Thanks,


Sunil Safare


Sunil,



I am trying to accomplish separating the requests to two different tasks based on their location.


Christopher Dan
Kilo Contributor

This is the full script I replaced .cmn_location with location, since the variable is .location and the reference table is the .cmn_location.



2015-10-21 08_51_29-ServiceNow.jpg