Skip to main content
MADink_Designs27
Inspiring
January 9, 2018
Answered

Script that Triggers if Part of Value is Matched

  • January 9, 2018
  • 2 replies
  • 964 views

I'd like to write a script that matches specific text in part of the field value but not all of it. Is there a way to script that?

The logic would be if the field CONTAINS this specific text, change the text color. If not, keep the text color as black.

Here's what I've tried (tried in both validation and format script with no luck):

if(event.value >= "(T)") {

event.textColor = color.red;

}

else {

event.textColor = color.black;

}

Any suggestions?

This topic has been closed for replies.
Correct answer try67

If you want to check whether this string is anywhere within the value, use this:

if (event.value.indexOf("(T)")!=-1) {

2 replies

try67
Community Expert
Community Expert
January 9, 2018

You're using the wrong operator. ">=" means "larger than or equal to", which doesn't apply to strings.

Replace it with "==".

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 9, 2018

If you want to check whether this string is anywhere within the value, use this:

if (event.value.indexOf("(T)")!=-1) {

MADink_Designs27
Inspiring
January 9, 2018

If I change "event" to the defined doc level variable, It simply changes to red regardless. I want it to only change if "(T)" is present in the value.