Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Custom Calculation script issues

Community Beginner ,
Apr 12, 2023 Apr 12, 2023

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 < 8) event.value = TC*0;

TOPICS
JavaScript , PDF forms
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2023 Apr 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 < 8) 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 12, 2023 Apr 12, 2023

Thanks for the quick responseScreen Shot 2023-04-12 at 9.20.17 AM.pngScreen Shot 2023-04-12 at 9.20.40 AM.pngScreen Shot 2023-04-12 at 9.24.30 AM.png, 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.

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2023 Apr 12, 2023

Change the field calculation order.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 12, 2023 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2023 Apr 12, 2023
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 12, 2023 Apr 12, 2023
LATEST

Works perfectly! Thank you for the help!

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