Use Contains Function

I would like to use the contains function to determine whether a substring exists in a given string. When I use the contains function, I get an error that the function is not defined. When I try to add "import java.lang.String;", I get the error stating "Cannot use import statement outside of module". An example of the code is below.

I need assistance on how to either:

  • Perform a search of a string for a define substring (examples: Does this string include "XYZ"

  • Include an import statement so I can import the class that includes the contains function

     var ReferralReasonText;
     ReferralReasonText = fd.field('RefReason').value;
     
     if(ReferralReasonText.contains("MTHFR")) {
     
         fd.control('RefRsnWarning').text = 'Found it!';
     
     } else {
     
         fd.control('RefRsnWarning').text = 'Not found!';
     
     }

Would includes work for you instead?
if(ReferralReasonText.includes('MTHFR'))

1 Like

that worked!!! Thanks so much!