Copy link to clipboard
Copied
I have a form with 3 columns that contain package tracking numbers. I would like to add a "package count" field that counts how many fields in each column contain input. For instance, "Total FedEx" would look at all cells named FEDEX1, FEDEX2 ...FEDEX40 and provide a package count.
As "Custom calculation script" of "Total FedEx" field use this:
var total = "";
for (var i=1; i<=40; i++) {
if (this.getField("FEDEX"+i).valueAsString != "") total++;
}
event.value = total;
Copy link to clipboard
Copied
As "Custom calculation script" of "Total FedEx" field use this:
var total = "";
for (var i=1; i<=40; i++) {
if (this.getField("FEDEX"+i).valueAsString != "") total++;
}
event.value = total;
Copy link to clipboard
Copied
That works great, and eSy to customize for different carriers. Is there a way to make the total appear in Parentheses?
Copy link to clipboard
Copied
Yes, change last line like this:
event.value = "("+total+")";
Copy link to clipboard
Copied
Can I use this same calculation script to count the total number of persons signing onto a form? The form has 60 text fields, 20 to print name, 20 to digitally sign and 20 for badge numbers, at the top right corner I have a text field titled "Total Workers" which is were I want the total to be calculated.
I change (var i=1; i<=40; i++) to (var i=1; i<=20; i++) & if (this.getField("FEDEX"+i).valueAsString != "") total++; to if (this.getField("PRINT NAME"+i).valueAsString != "") total++; . However, the script did not calculate. Is there something else that I need to change or something that I'm doing wrong?
Copy link to clipboard
Copied
Are your fields named: PRINT NAME1,PRINT NAME2...PRINT NAME20?
Your code should look something like this:
var total = "";
for (var i=1; i<=20; i++)
if (this.getField("PRINT NAME"+i).valueAsString != "") total++;
event.value = total;
Copy link to clipboard
Copied
You're correct, the text fields are named just as you mentioned.
I just tried the code but it doesn't calculate anything in the "total worker" when I type in the text fields.
Is there anything something that I have to do with the text fields before the code works?
Copy link to clipboard
Copied
Please look in the Console window to see if any errors are reported.
Display the console window with Ctrl-J
Also, post the exact code you are using.
Copy link to clipboard
Copied
Below are the errors that console shows.
TypeError: this.getField(...) is null
3:Field:Calculate
TypeError: this.getField(...) is null
3:Field:Calculate
TypeError: this.getField(...) is null
3:Field:Calculate
TypeError: this.getField(...) is null
3:Field:Calculate
TypeError: this.getField(...) is null
3:Field:Calculate
Below is the exact script that I have in the custom calculation script field.
var total = "";
for (var i=1; i<=20; i++)
if (this.getField("PRINT NAME"+i).valueAsString != "") total++;
event.value = total;
Copy link to clipboard
Copied
The errors reported in the console would suggest that the field name used in the script is incorrect.
Make sure your field names exactly match the name used in the script.
"PRINT NAME1" ..... to .... "PRINT NAME20"
Copy link to clipboard
Copied
You should test out this script in the Console Window before putting it in the field script.
To use it in the console, just remove the last line "event.value = total"
This will tell you exactly where the code is going wrong.