• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit Search
0

Searching text field using script with wild card, key words, or not exact words

New Here ,
Feb 01, 2023 Feb 01, 2023

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.

 

 

TOPICS
General troubleshooting , How to , JavaScript

Views

279

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 02, 2023 Feb 02, 2023

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"}

Votes

Translate

Translate
Community Expert ,
Feb 01, 2023 Feb 01, 2023

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?).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2023 Feb 02, 2023

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"}

  • employee enters cape spencer, Cape Spencer, spencer, or Spencer in the field, it will be recognized as "spen"
  • and Sitka, or SITKA as "sit"
  • it will then give the 320 miles

Another ex:

if(this.getField("PlaceRow1").value=="cea" && this.getField("PlaceRow2").value=="kut"){event.value="31 miles"}

  • employee enters ocean or ocean cape but the script will know its for "cea"
  • if they enter yakutat or Yakutat in the the field, the script will recognize "kut"
  • it will then give the 31 miles

 

I apologize if it isn't that clear. I attached an example of what I'm working on

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

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"}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

LATEST

THANK YOU!!!! IT WORKED PERFECTLY!!!! YOU ARE AWESOME!!!!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines