Copy link to clipboard
Copied
I am making a form to quote out multiple products, where the customer receives a rebate. The product is taxable, the rebate does not effect the taxable value of the quote. The way I am formatting it, Product & Rebates are added in the body of the quote.
For example, if a product is $100, the rebate is $50 (written as -75), and the Sales Tax is 7%, I need to subtotal to read as $100, and not $25, since the sum adds positive and negative number together.
How can I write a custom script where all positive fields are added together, but if the value of a field is negative, the calulation treats it as a value of 0, rather than it's negative value?
Copy link to clipboard
Copied
You can use this code as the custom calculation script of your field (adjust the first line, of course):
var fieldsToAdd = ["Text1", "Text2", "Text3"]; // Replace with actual field names
var total = 0;
for (var i in fieldsToAdd) {
var f = this.getField(fieldsToAdd[i]);
var v = Number(f.valueAsString);
if (v>0) total+=v;
}
event.value = total;
Copy link to clipboard
Copied
Which Adobe app or service are you using?
Copy link to clipboard
Copied
I am using Adobe Acrobat Pro. I have used many custom calulations before with great success, but this one illudes me.
Moving from Using the Community (which is about the forums) to the correct forum... Mod
To ask in the forum for your program please start at https://community.adobe.com/
Copy link to clipboard
Copied
You can use this code as the custom calculation script of your field (adjust the first line, of course):
var fieldsToAdd = ["Text1", "Text2", "Text3"]; // Replace with actual field names
var total = 0;
for (var i in fieldsToAdd) {
var f = this.getField(fieldsToAdd[i]);
var v = Number(f.valueAsString);
if (v>0) total+=v;
}
event.value = total;
Copy link to clipboard
Copied
This is perfect! Thank you!

