Add validation script to multiple fields using setAction?
Copy link to clipboard
Copied
I want to add this script to multiple fields as a validation script.
if (event.value==0) (event.value = "");
I created a document level function:
function valZero()
{
if (event.value==0) (event.value = "");
}
I tried running it in the console and also as a custom command
this.getField("FieldName").setAction("Validate"," valZero();");
I also tried writing it out instead of using my function:
this.getField("FieldName").setAction("Validate"," if (event.value==0) (event.value = "");");
What am I doing wrong?
Copy link to clipboard
Copied
Hi,
Have you tried using the code on a field validation script using the UI to make sure it functions as expected?
And what is not working? a bit more information would be useful, is there anything in the console?
Copy link to clipboard
Copied
You have several errors both in your function and in your second setAction command, which is why neither worked.
In the function change this line:
if (event.value==0) (event.value = "");
To:
if (event.value==0) event.value = "";
In the second setAction you also didn't escape the quotes. So change this:
this.getField("FieldName").setAction("Validate"," if (event.value==0) (event.value = "");");
To this:
this.getField("FieldName").setAction("Validate","if (event.value==0) event.value = \"\";");
I would use the function version, though, if you want to apply it to multiple fields.
Copy link to clipboard
Copied
So if I fix the syntax in the function, is this the correct statement to run in the console?
this.getField("FieldName").setAction("Validate"," valZero();");
Can you explain why the second set of parantheses needed to be removed?
Copy link to clipboard
Copied
Because a block of code is delimited with curly brackets, or none at all (if it's a single line).

