Issue with custom calculation script
I am converting an Adobe DC form to an AEM form, and having an issue with converting a script, and need some help because the syntax check is fine, and do not receive any errors in preview, so not sure what is wrong.
I have the following code from the custom calculation script in my Adobe DC form
// Initialize variables
var i, v, num = 0, sum = 0;
// Loop through the input fields
for (i = 1; i <= 13; i++) {
v = +getField("A" + i).value;
if (v !== 0) {
// increment the non-blank/zero field counter
num++;
// add the field value to the running total
sum += v;
}
}
// Calculate the average
if (num) {
event.value = sum / num;
} else {
// All fields are empty, so set to blank
event.value = "";
}
event.value = (event.value - 0.005).toFixed(2);
if (event.value <= 0) event.value = "";
and when I add that to the calculate, script for the form in AEM, it appears fine, but nothing appears in the field.
Now all of the "A1 - A13" fields are in separate subforms, so not sure if that makes a difference with the script or not, but wanted you to know how my form is setup.
On another related question, will this form work, or is there any tweaks I need to make if some of the pages containing these "A" fields are hidden, until a button is clicked? I would think the code would still work, but just wanted to ask to make sure.
Thanks in advance for any help?