- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2017 01:26 PM
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';
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 03:52 PM
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')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2017 02:52 PM
I was going after the wrong company variable name. I set the script to SJCF and it needed to be SJC. I corrected and have successful tests now. I'll mark the answer correct. Thanks again for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2017 04:38 PM
Ran other tests through and not getting correct results. The battle continues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 11:53 AM
My recommendation would be put put some gs.log() statements to log the values so you can compare. For example:
answer = ifScript();
function ifScript(){
var Companies = ["SJCF","SHE"];
var validCompany = Companies.indexOf(current.variables.company_code) >-1;
var JobCodes = ["2000","2019","2057","2064","2086"];
var invalidJobCodes = JobCodes.indexOf(current.variables.job_code) >-1;
gs.log("company_code: " + current.variables.company_code + ", validCompany: " + validCompany + ", job_code: " + current.variables.job_code + ", invalidJobCodes: " + invalidJobCodes).
if(validCompany && !invalidJobCodes){
return 'yes';
} else {
return 'no';
}
}
Then you can go to the logs and see the output and make sure your code is setup correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 12:11 PM
Thanks Michael. I did add gs.log statements but nothing shows when I use the arrays. The only way I could get this to work was to create two ifScripts. One to evaluate the Company Code, and if found, jump to the next ifScript to to evaluate the Job Codes. The below scripts are working after running a few tests. I will try the script that you provided again just to verify that I didn't miss anything.
answer = ifScript();
function ifScript(){
var company = current.variables.company_code;
if(company == "SHE" || company == "SJC"){
gs.log('Company name ' + company);
return 'yes';
}
else{
return 'no';
}
}
answer = ifScript();
function ifScript(){
var jobCode = current.variables.job_code;
if(jobCode == "2000" || jobCode == "2019" || jobCode == "2057" || jobCode == "2064"){ //Invalid Job Codes
gs.log('Job Code ' + jobCode);
return 'no';
}
else{
return 'yes';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 12:56 PM
I added the script and ran two tests:
Test 1: Used a valid company code (SJC) and valid Job Code (2045). Expected Result = Yes - Actual Result = No - Company wrongly evaluated
Test 2: Used a valid company code (SJC) and invalid Job Code (2000). Expected Result = No - Actual Result = No, but company and Job Code were wrongly evaluated
gs.log Results
Both Tests showed a false value for Company, and both should have been true.
Both Tests showed a false value for Invalid Job Codes and TEST 2 should have been true.