Indexof() issue

Derek10
Tera Expert

I'm having a quandary trying to see why this is not working, I'd like to think it is a fairly simple thing and I have been looking at screens too long this week!

answer = ifScript();
//
var location = current.variables.requested_for.location.getDisplayValue();

(sample value of location is UKBAS1 -blah blah blah)

function ifScript() {
if (location.toString().indexOf('UKBAS1') >= 0) {
  return 'yes';
 
}
return 'no';
}

I've tried == 0, != -1 as well. Just looking to test for a match if the string contains UKBAS1

Has to be something simple here

1 ACCEPTED SOLUTION

Brian Lancaster
Tera Sage

Hello Derek,


I am able to do thing like this.   The only difference between my code and yours is where I declare my variables.   I declair them in the fucation not before it.


answer = ifScript();
//


function ifScript() {


var location = current.variables.requested_for.location.getDisplayValue();
if (location.toString().indexOf('UKBAS1') >= 0) {
  return 'yes';
 
}
return 'no';
}


View solution in original post

6 REPLIES 6

Oh wow, Brian nailed it.   I missed that too.   It's simply an ordering issue.   answer = ifScript(); gets run and doesn't care about var location:



answer = ifScript();


var location = current.variables.requested_for.location.getDisplayValue();



should be:



var location = current.variables.requested_for.location.getDisplayValue();


answer = ifScript();



or like Brian said, declare var location inside the ifScript() function if it doesn't need to be used outside of that function...


Thank you gentlemen!



I have been working on this 1 aspect for 3 hours. Time for drinks! Open up a tab on me!



Derek