Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Average ignore blanks but does not ignore 0s

New Here ,
Aug 17, 2020 Aug 17, 2020

Looking for a Document level script and Field level script that will ignore blanks in the average but will count 0s in the average. I have several fields for subaverages and a cumulaitve average. I have been using these two scripts to ignore blanks but now they want the 0s in the averages. Any suggestions would help!

 

function calcAverage(fields, ignoreBlanks) {
var total = "";
var n = "";
for (var i in fields) {
var f = this.getField(fields[i]);
if (f==null) {
console.println("Error! Can't locate a field called: " + fields[i]);
continue;
}
if (f.valueAsString=="" && ignoreBlanks) continue;
total+=Number(f.valueAsString);
n++;
}
if (n=="") event.value = "";
else event.value = total/n;
}

 

calcAverage(["PLO_1_a", "PLO_1_b", "PLO_1_c", "PLO_1_d", "PLO_1_e"], true, true);

TOPICS
Acrobat SDK and JavaScript
448
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 17, 2020 Aug 17, 2020
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2020 Aug 17, 2020

Tried that and it's still not working. Any other suggestions?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2020 Aug 17, 2020
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines