Copy link to clipboard
Copied
Hello,
I have been trying to write a script to total my required and suggested totals, but I am unable to get my required or suggested total to calculate correctly.
Previously, I was using this script to total my RequiredTotal and that was working fine, until I started clicking on the drop down menus then it really broke and just combined the numbers rather than sum them. For example, instead of adding 70 and 229 together it was writing 22970.
Here is the short form of the script I was using for the summation:
// sum of the RequiredTotal
event.value = (this.getField("Required_2").value) + (this.getField("Required_3").value) + (this.getField("Required_4").value) + (this.getField("Required_5").value) + ... up to (this.getField("Required_14").value);
Then I was just adding an if statement to comeback with a null string if 0:
// if value is zero replace with null string
if (event.value == 0) event.value = "";
For the other scripts I used a simple multipication script with the same null string clause:
// get value of Required_14
event.value = (this.getField("RequiredRow14").value) * (this .getField("Unit Price_14").value);
// if value is zero replace with null string
if (event.value == 0) event.value = "";
That multipication script works great on all my rows and the summation almost works, but then eventually starts mashing the numbers together as previously mentioned. I switched to using the pre written sum function Acrobat offers and now it's summating just fine, but that won't work for my suggested total.
For the SuggestedTotal, I only want it to include a value and create a sum when the value is > the RequiredTotal. So my summation script looks the same as the RequiredTotal except I added (this.getField("RequiredTotal").value); to the end of my suggested script.
I also added an if statement to comeback with a nullstring if the value is <= RequiredTotal:
// if SuggestedTotal is <= RequiredTotal replace with null string
if (event.value <= (this.getField("RequiredTotal").value)) event.value = "";
The issue I'm having with this one is the SuggestedTotal won't even calculate half the time and the other half of the time it does that number mashing thing that I described for the RequiredTotal.
I'm kind of at my wits end here, so any assistance/clarity would be GREATLY appreciated!
Here is a screenshot of the row/column names:
Here is a screenshot of the calculation error:
Copy link to clipboard
Copied
Check the fields calculation order.
Copy link to clipboard
Copied
Check the fields calculation order.
Copy link to clipboard
Copied
The order was correct, but I actually just found the answer this morning from one of your other comments on someone else's post. I needed to add a Number function to every field and after I did that it all calculated correctly.
So a big thanks to you in the past and now!
So for anyone else who's confused my string looks like this now and is working perfectly:
// sum of the SuggestedTotal
event.value = Number(this.getField("Suggested").value) + Number(this.getField("Suggested_2").value) + Number(this.getField("Suggested_3").value) + Number(this.getField("Suggested_4").value) + Number(this.getField("Suggested_5").value) + Number(this.getField("Suggested_6").value) + Number(this.getField("Suggested_7").value) + Number(this.getField("Suggested_8").value) + Number(this.getField("Suggested_9").value) + Number(this.getField("Suggested_10").value) + Number(this.getField("Suggested_11").value) + Number(this.getField("Suggested_12").value) + Number(this.getField("Suggested_13").value) + Number(this.getField("Suggested_14").value) + Number(this.getField("RequiredTotal").value);
// if SuggestedTotal is <= RequiredTotal replace with null string
if (event.value <= (this.getField("RequiredTotal").value)) event.value = "";
Thanks again!

