Expand my Community achievements bar.

If auto populate text value contains "X", change to "Y"

Avatar

Level 3

I am not 100% sure if this is possible. I have a field which auto populates from a choice made in a drop down menu. There are multiple values of "Nullxxx" (Null001, Null002, Null003, etc.), plus other values. I am looking to have this field value change to "N/A" rather than the value of Nullxxx, anytime it sees "Null". If it doesn't see Null, then I want the value to stay as it is imported.

So I would assume something like, If the field value contains "Null", then change to N/A, Else do nothing. I am just not sure if a field value on an auto populated field is possible to change on the fly?

Thanks, Gary

5 Replies

Avatar

Level 8

Try putting this in the ready:form event of your field:

if (/^null/i.test(this.rawValue))

this.rawValue=null;

Kyle

Added start of string meta-character to regular expression just in case user puts string "null" in text somewhere.

Avatar

Level 3

That didn't do anything. Plus, since the field is empty until populated from the drop-down, wouldn't it need to go into the Change event? And the null values are all Null (the word not the expression) with 3 numbers (Null###). So it needs to test/search for the word "Null" and replace with N/A if it exists. If not I need the value to populate as-is, not be empty/null.

Avatar

Level 8

Sorry, I misunderstood. I thought it was data being imported into a field whose values could be Null###.

Will the values in the dropdown be dynamic properties (ie populated at run-time)? Do you want all the values in the dropdown to change from Null### to N/A or just when the user selects Null###?

If it's the latter, put this in the change event:

if (/^null/i.test(xfa.event.newText))

xfa.event.change="N/A";

Kyle

Avatar

Level 3

Kyle,

There are three values in the drop-down that are comma delimited in the binding tab. The text chosen (Null### is never a choice, just a value) will split those values to populate three different fields. The auto populated field in question can have a value of Null###. But there are also values in that field that will not be Null### as a value. So when a value of Null### does populate the field, it would need to change to N/A. If it is a value that is not Null###, it will need to populate as-is.

So there are two things that need to happen:

  1. If the value contains Null###, it needs to change to N/A. Null### value example would change Circuit # value would change from Null209 to N/A.
  2. If it does not contain Null###, it needs to populate as-is. Not Null### value example. Circuit # value would stay 00023 and not change.

I hope that is more clear? I am adding a couple of screen shots to help.

Null### value

Null.jpg

Not Null### value

NotNull.jpg

Gary

Avatar

Level 8

You can use something like this:

if (/^null/i.test(CircuitValue))

Circuit.rawValue="N/A";

else

Circuit.rawValue=CircuitValue;

Since I don't know what your code looks like to split the values, the code above assumes the variable CircuitValue is what is meant to be put in your Circuit # field.

As you can see from my previous posts though, /^null/i.test(yourstringhere) is the underlying condition that tests whether yourstringhere starts with 'null'.

Kyle