ifScript Activity in Workflow

michaelcory
Giga Expert

I have the following IF Activity script in Workflow (global table).   Variables are held in a custom Import table.   If I just evaluate the companyCode variable, the script works.   When I add the jobCode variable values the script does not evaluate correctly.   I want to return NO if the companyCode matches, but the jobCode does not.   Is there some other way to script this?

answer = ifScript();

function ifScript(){

  var companyCode = current.variables.company_code;

  var jobCode = current.variables.job_code;

  if(companyCode == 'SJC' || companyCode == 'SHE' && (jobCode != '2000' || jobCode != '2019' || jobCode != '2057' || jobCode != '2064' || jobCode != '2086' || jobCode != '2088' || jobCode != '2130' || jobCode != '2208')){

  return 'yes';

  } else {

  return 'no';

  }

}

1 ACCEPTED SOLUTION

Mike,



let me clarify the requirement, if companycode is either SJC or SHE and jobcode is not one of 2000,2019,2057,2064,2086,2088,2130,2208 then you need to return yes. am i right?



so shouldn't the if statement be:



  if((companyCode == 'SJC' || companyCode == 'SHE') && jobCode != '2000' && jobCode != '2019' && jobCode != '2057' && jobCode != '2064' && jobCode != '2086' && jobCode != '2088' && jobCode != '2130' && jobCode != '2208')



View solution in original post

14 REPLIES 14

Abhinay Erra
Giga Sage

What is the variable type of job_code?


job_code is a string variable from the import table.


rob_pastore
ServiceNow Employee
ServiceNow Employee

your if statement is filled with 'ORs'.



If you say if a number is not 2 or a number is not 3 - it will always return true.



Negation and or do not play well.


Mike,



let me clarify the requirement, if companycode is either SJC or SHE and jobcode is not one of 2000,2019,2057,2064,2086,2088,2130,2208 then you need to return yes. am i right?



so shouldn't the if statement be:



  if((companyCode == 'SJC' || companyCode == 'SHE') && jobCode != '2000' && jobCode != '2019' && jobCode != '2057' && jobCode != '2064' && jobCode != '2086' && jobCode != '2088' && jobCode != '2130' && jobCode != '2208')



Your clarification is correct Ajit and the script works.   Thank you for the reply.   I will mark your answer correct.   I originally tried that same script using the OR operator instead of the AND.   I see the errors of my ways now and it seems I have made a mountain out of a mole hill.   Thank you all for your assistance.