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

Average ignore blanks but does not ignore 0s

New Here ,
Aug 17, 2020 Aug 17, 2020

Copy link to clipboard

Copied

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

Views

294

Translate

Translate

Report

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

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

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