Copy link to clipboard
Copied
Hi,
I'm trying to come up with a script that searches two different text field with words (in this case a location/place) and yields a result (mileage). ex. if text field 1 contains XXX and text field 2 contains XXX then it equals XXX
So far, I was able to somehow come up with the following:
if(this.getField("PlaceRow1").value=="Cape Spencer" && this.getField("PlaceRow2").value=="Sitka"){event.value="320 miles"}
The script works but the downside is that it only works with "exact words and it is also case sensitive" which will not work out since not everyone will type how I have it recorded.
How do I change the above script so that it will not be case senstiive or doesn't follow exact wording?
For example, if they type SITKA, the script will still recognize it as Sitka and if they type just Spenc, it will work with Cape Spencer.
Note: I have ZERO experince with scripting, I was just lucky that the above script happened to partially worked out from all the things I've read. If possible, may you please kindly make it as simple as possible for me to understand. Thank you so much in advance.
You can do it using a Regular Expression, for example:
if (/spen/i.test(this.getField("PlaceRow1").value) && /sit/i.test(this.getField("PlaceRow2").value)){event.value="320 miles"}
Copy link to clipboard
Copied
First part is easy to do. Second part is much trickier.
What's the logic behind "Spenc" matching "Cape Spencer"? What about "Spen", or "Spe", "Sp", or just "S"? And if they type just "S", shouldn't that also match "Sitka"? In other words, you have to define very clearly what are the rules for matching a partial string, or a fuzzy one (what if they enter "Cape Spancer", for example?).
Copy link to clipboard
Copied
I mean, I was hoping there's a way for the script to recognize not case sensitive or certain letters of the words.
For instance, if the script says:
if(this.getField("PlaceRow1").value=="spen" && this.getField("PlaceRow2").value=="sit"){event.value="320 miles"}
Another ex:
if(this.getField("PlaceRow1").value=="cea" && this.getField("PlaceRow2").value=="kut"){event.value="31 miles"}
I apologize if it isn't that clear. I attached an example of what I'm working on
Copy link to clipboard
Copied
You can do it using a Regular Expression, for example:
if (/spen/i.test(this.getField("PlaceRow1").value) && /sit/i.test(this.getField("PlaceRow2").value)){event.value="320 miles"}
Copy link to clipboard
Copied
THANK YOU!!!! IT WORKED PERFECTLY!!!! YOU ARE AWESOME!!!!