Or condition in a basic Script

jobdexters
Kilo Contributor

Hi All,

I am not very good in scripting and I am tying to make an IF condition in a workflow.

Since the OOB function is not properly working, I created the the following:

answer = (current.variables.u_pds2_server_location.u_display_name=="LocationA,Location (B),Location (C)") ? "yes" : "no";

The Location (B) and Location (C) is just named like this because they have these names in the table.

What I try to do is that the script checks if either one of the 3 locations is in the field, with a yes or no output..

So if Location is LocationA or Location (B) or Location (C) then yes

If location is not LocationA or Location (B) or Location (C) then no

I guess I need another differentiation between then other then the comma I used

Anyone? Thanks!  

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Job,



Try this one.


var loc = current.variables.u_pds2_server_location.u_display_name


answer   = (loc == 'LocationA' || loc == 'LocationB' || loc == 'Locationc')? 'yes':'no'


View solution in original post

5 REPLIES 5

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hello Job,



What about something like:



switch(current.variables.u_pds2_server_location.u_display_name)


  {


  case 'Location A':


  answer = yes;


  break;


 


  case 'Location B':


  answer = yes;


  break;


 


  case 'Location C':


  answer = yes;


  break;



  default:


  answer = no;


  }



Regards,


Sergiu


Thanks Sergiu, but it came back with a bunch of errors, which I will spare you


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Job,



Try this one.


var loc = current.variables.u_pds2_server_location.u_display_name


answer   = (loc == 'LocationA' || loc == 'LocationB' || loc == 'Locationc')? 'yes':'no'


Thanks Pradeep, it did the trick!