Copy link to clipboard
Copied
I am trying to write a script that verifies that fieldA and fieldB do not contain identical strings. And alerting the user if they are the same. I have the following script (located in the validation of fieldB, but when I enter the same text in both boxes, no alert appears.
if(this.getfield("fieldA".value) == event.value) {
app.alert("Must be different than fieldA");
}
Copy link to clipboard
Copied
You have errors in your code. Check the JS Console.
Copy link to clipboard
Copied
When comparing field values like it seems you want, you should use the valueAsString field property, so the code could look like:
if (this.getField("fieldA").valueAsString == event.value) {
app.alert("Must be different than fieldA");
}
Note that event.value will always be a string in this context.
Copy link to clipboard
Copied
JavaScript is case sensitive for everything.
What should happen if both fields are empty?
Your script should allow for the fields to have their values be changed to another value or even to no value.
Copy link to clipboard
Copied
Thank you all. I found the errors in my script. The check works with .value or .valueAsString. I added a qualifier to not perform the check if fields left blank.