Skip to main content
Participant
April 12, 2023
Question

Custom Calculation script issues

  • April 12, 2023
  • 2 replies
  • 1119 views

I have an acrobat order form with 104 products. People can buy an individual item or cases of that item. I've been able to calculate the product cost per item and per case.

 

My issue is that there are discount conditions based on the number of cases purchased:

  • Less than 8 cases = no discount on total invoice
  • 8-23 cases = 10% discount on total invoice
  • 24 or more = 20% discount on total invoice

 

I have a tally of all cases purchased called "Case Qty" (CQ), and I have a tally of the cost of all items purchased called "Total Cost" (TC).  In a cell called "Discount Cost", I have a CCS that seems to be working, with a few exceptions: if there are exactly 8 cases ordered, no discount is applied to the cell. Also, sometimes if you meet the criteria for a discount then change the case value so that it doesn't meet the criteria, the discount value is still applied to the cell. Can anyone see what I'm doing wrong? Thanks so much for the help.

 

var CQ = this.getField("Case Qty").value;
var TC = this.getField("TOTAL COST").value;
if(( CQ > 7 ) && (CQ < 24 )) event.value = TC*0.90;
else if( CQ > 23 ) event.value = TC*0.80;

else if( CQ < 😎 event.value = TC*0;

This topic has been closed for replies.

2 replies

Bernd Alheit
Community Expert
Community Expert
April 12, 2023

Change the field calculation order.

Participant
April 12, 2023

Thanks Bernd.
Would you start with highest criteria value and end with lowest? >=24, >=8 && <=23, <8
Still having some issues with the discount cell. Attached is a video showing what happens when values are entered and changed. The column on the right is my invisible Case Qty tally.

 

Thanks again.

JR Boulay
Community Expert
Community Expert
April 12, 2023

Try this, be sure to use it as a Calculation script:

 

var CQ = this.getField("Case Qty").value;
var TC = this.getField("TOTAL COST").value;
if( CQ < 😎 event.value = TC*0;
else if(( CQ >= 8 ) && (CQ <= 23 )) event.value = TC*0.90;
else if( CQ > 23 ) event.value = TC*0.80;

Acrobate du PDF, InDesigner et Photoshopographe
Participant
April 12, 2023

Thanks for the quick response, JR.

 

Still having issues with the discount not showing up for exactly 8 cases purchased, also the discount being applied to the cell when conditions are initially met then changed so they are not.