# Calculations Not working in my Function

Participant ,
Mar 14, 2021 Mar 14, 2021

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

928

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Adobe Community Professional , 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.

Likes

8 Replies 8
Mar 14, 2021 Mar 14, 2021

Copied

Why does you use the following:

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Mar 15, 2021 Mar 15, 2021

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";``

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 15, 2021 Mar 15, 2021

Copied

Any error?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Mar 15, 2021 Mar 15, 2021

Copied

@Bernd Alheit
Yes, still not working!  😞

This code wont work even alone:

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 15, 2021 Mar 15, 2021

Copied

LATEST

What is the value of idx?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 15, 2021 Mar 15, 2021

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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Mar 15, 2021 Mar 15, 2021

Copied

@try67
What would be the alternative to find and map?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 15, 2021 Mar 15, 2021

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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources