Copy link to clipboard
Copied
I have a column of 15 rows of fields. The fields are named comp# (1-15). I want to count all of the fields with either CI, FO, L, or NS. I have the code below, but I don't know how to incorporate the other 3 options.
var total = "";
for (var i=1; i<=15; i++) {
if (this.getField("comp"+i).valueAsString == "CI") total++;
}
event.value = total;
Copy link to clipboard
Copied
Use this:
var total = 0;
for (var i=1; i<=15; i++) {
var f = this.getField("comp"+i).valueAsString;
if (f == "CI" || f == "FO" || f == "L" || f == "NS") total++;}
event.value = total;
Copy link to clipboard
Copied
Use this:
var total = 0;
for (var i=1; i<=15; i++) {
var f = this.getField("comp"+i).valueAsString;
if (f == "CI" || f == "FO" || f == "L" || f == "NS") total++;}
event.value = total;
Copy link to clipboard
Copied
Thanks!
Copy link to clipboard
Copied
Sorry, 1 more question. How do I create a custom validation for this field to make sure the person only enters 1 of the 4 valid options. Otherwise, the count would be incorrect. I would like a popup of the error and for the incorrect value to be removed. I've tried:
var f = this.getField("comp1").value;
if (f != "CI" || f != "FO" || f != "L" || f != "NS" || f != "")
event.value = app.alert("Invalid entry. Enter a valid code from the options listed below");
Copy link to clipboard
Copied
Sorry, I figured it out.
event.rc = true;
if (event.value != "" && event.value != "CI" && event.value != "FO" && event.value != "L" && event.value != "NS")
{
app.alert("Invalid entry. Enter a valid code from the options listed below.");
event.rc = false;
}