• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• Calculating Sum - Adding Fee to Most of the Items

# Calculating Sum - Adding Fee to Most of the Items

Community Beginner ,
Feb 27, 2024 Feb 27, 2024

Copied

Calculating Sum - additional fee variable

I want to calculate the sum of 29 fields.

There is a \$30 base fee that gets added to the sum of the fields.

However, there are two items in the list that do not get charged that additional 'base fee' of \$30 (highlighted in the image)

Right now, I am using this simplified field notation:

(Cost1+Cost2+Cost3+Cost4+Cost5+Cost6+Cost7+Cost8+Cost9+Cost10+Cost11+Cost12+Cost13+Cost14+Cost15+Cost16+Cost17+Cost18+Cost19+Cost20+Cost21+Cost22+Cost23+Cost24+Cost25+Cost26+Cost27+Cost28+Cost29+Cost30+30)

What's the best way for me get the correct calculation?

TOPICS
Create PDFs , Modern Acrobat , PDF , PDF forms

Views

239

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 Expert , Feb 27, 2024 Feb 27, 2024

Try this code as the custom calculation script of the total field:

var total = 0;
for (var i=1; i<=30; i++) {
var cost = Number(this.getField("Cost"+i).valueAsString);
total+=cost;
if (cost>0 && i!=1 && i!=24) addFee = true;
}
event.value = total;

6 Replies 6
Community Expert ,
Feb 27, 2024 Feb 27, 2024

Copied

So you want to add the fee if any of the other fields are selected, basically? Do all of these fields have a value, or does the user enter one into them? Does it not also rely on the quantity fields (Cost*Quantity)?

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 Beginner ,
Feb 27, 2024 Feb 27, 2024

Copied

The fee only gets added to the sum, not to the items indivuidually. When the user enters a value, the cost for that item is set to calculate. Then the sum of all of the individual fields is calculated. Right now, the "Total Permit Fee" field also adds \$30 to the calculation (that's for the 'base fee' charged by the department. Hoever, there are two items in the list that should not be assessed that additional \$30 fee.

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 Expert ,
Feb 27, 2024 Feb 27, 2024

Copied

I'm trying to understand how it should work practically, though. Say the user entered qty 1 for Gas Safety only. Then the cost for that field is calculated to be 50 (for example). So the total is just 50. That's clear.

But if they enter "1" for Boiler then the cost for that field becomes 30, say. So what's the total now? Isn't it 50+30+30 (the fee because of Boiler) = 110?

There's no way not to apply the fee to these two items, too, unless they are the only ones that are selected...

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 Beginner ,
Feb 27, 2024 Feb 27, 2024

Copied

"There's no way not to apply the fee to these two items, too, unless they are the only ones that are selected..."

That's the part that I want to fix. If the user only selects one (or both) of the highlighted items, how can I prevent the base fee of \$30 from being added to the Total Permit Fee field?

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 Expert ,
Feb 27, 2024 Feb 27, 2024

Copied

Try this code as the custom calculation script of the total field:

var total = 0;
for (var i=1; i<=30; i++) {
var cost = Number(this.getField("Cost"+i).valueAsString);
total+=cost;
if (cost>0 && i!=1 && i!=24) addFee = true;
}
event.value = total;

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 Beginner ,
Feb 27, 2024 Feb 27, 2024

Copied

LATEST

Thank you! It's perfect!

I appreciate your time to provide this solution. I'm definitely a novice when it comes to using java script for calculations.