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

Calculations Not working in my Function

Participant ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

I have made a form with the purpose of having multiple dropdowns for inserting an 'ID number' which would then populate the following text fields: 'description,' & 'total'

The problem I am having the calculations in SetTotalValues:

TypeError: (intermediate value).find is not a function 240:Document-Level:SetFieldValues

  var DeptData = { 
   0:{
  description: "SUBTOTAL",
  description2: "20% BUILDERS MARGIN",
  description3: "SUBTOTAL W/ MARGIN",
  description4: "QBCC Home Warranty Insurance",
  description5: "TOTAL",
  description6: "GST",
  description7: "TOTAL W/ GST",
  description8: "******************************************************************************************************************" ,
      quantity: "",
      unit: "",
      price: ""
    },
  };
  function SetTotalValues(cID, idx) {
      this.getField("Desc"+(parseInt(idx))).value = DeptData[cID].description;
      this.getField("Desc"+(parseInt(idx)+1)).value = DeptData[cID].description2;
      this.getField("Desc"+(parseInt(idx)+2)).value = DeptData[cID].description3;
      this.getField("Desc"+(parseInt(idx)+3)).value = DeptData[cID].description4;
      this.getField("Desc"+(parseInt(idx)+4)).value = DeptData[cID].description5;
      this.getField("Desc"+(parseInt(idx)+5)).value = DeptData[cID].description6;
      this.getField("Desc"+(parseInt(idx)+6)).value = DeptData[cID].description7;
      this.getField("Desc"+(parseInt(idx)+7)).value = DeptData[cID].description8;
      this.getField("Total"+(parseInt(idx))).value = "122";;
      this.getField("Total"+(parseInt(idx)+1)).value = 0.2 * this.getField("Total"+(parseInt(idx))).value;
      this.getField("Total"+(parseInt(idx)+2)).value = this.getField("Total"+(parseInt(idx))).value + this.getField("Total"+(parseInt(idx)+1)).value;
      this.getField("Total"+(parseInt(idx)+3)).value = ([(this.getField("Desc"+(parseInt(idx)+3)).value)].map(getValue));
      this.getField("Total"+(parseInt(idx)+4)).value = this.getField("Total"+(parseInt(idx)+2)).value + this.getField("Total"+(parseInt(idx)+3)).value;
      this.getField("Total"+(parseInt(idx)+5)).value = 0.1 * this.getField("Total"+(parseInt(idx)+4)).value;
      this.getField("Total"+(parseInt(idx)+6)).value = this.getField("Total"+(parseInt(idx)+4)).value + this.getField("Total"+(parseInt(idx)+5)).value;
      this.getField("Total"+(parseInt(idx)+7)).value = "*****";
  }

Why don't the calculations work?
Any help is much appreciated!!!

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF forms

Views

1.6K

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

correct answers 1 Correct answer

Community Expert , Mar 15, 2021 Mar 15, 2021

find: run a loop on the array and return the first item that satisfies the desired condition.

map: run a loop on the array, processing all items in the desired way.

You can create your own functions that will do it and just call them with the array as a parameter.

Votes

Translate

Translate
Community Expert ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

Why does you use the following:

this.getField("Total"+(parseInt(idx)+3)).value = ([(this.getField("Desc"+(parseInt(idx)+3)).value)].map(getValue));

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
Participant ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

@Bernd Alheit 
Sorry, I left out another variable :

var getValue = total => [ [3300, 194.25], [4000, 197.5], [237000, 1281.65], [238000, 1286.3], [Infinity, 999999], ].find(([t]) => total <= t)[1];

 

I can't even make this script work by itself though:

this.getField("Total"+(parseInt(idx))).value = "122";

 

Thanks for your reply Bernd!

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
Community Expert ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

Any error?

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
Participant ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

@Bernd Alheit 
Yes, still not working!  😞

This code wont work even alone:

this.getField("Total"+(parseInt(idx))).value = "122";

 

 

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
Community Expert ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

LATEST

What is the value of idx?

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
Community Expert ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

I recommend not using these functions (find, map, etc.) in your code. They were only added to latest versions of Acrobat (and Reader) DC, and will not work in earlier versions. Stick to the code JavaScript functions and it will work every time.

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
Participant ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

@try67 
What would be the alternative to find and map?
Thanks for your help!

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
Community Expert ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

find: run a loop on the array and return the first item that satisfies the desired condition.

map: run a loop on the array, processing all items in the desired way.

You can create your own functions that will do it and just call them with the array as a parameter.

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