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

Custom Calculation Script to apply a conditional discount

New Here ,
Jan 23, 2017 Jan 23, 2017

I am trying to figure out how to write a custom calculation script for a discount on an order form.

There are several items on the order form (all $16.60 each).

I add all the items and multiply them by 16.60 for the TOTAL.

If the TOTAL is greater than $398.40 (= 24 items), then I want to give a new total that takes 5% off the total.

Can someone please help me create that formula? I have no idea how to make these javascript formulas. Thank you!!!

TOPICS
Acrobat SDK and JavaScript
710
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 ,
Jan 23, 2017 Jan 23, 2017

I probably would not just change the total without indicating why the total is no longer a multiple of $16.60 - I would have a filed called "SubTotal" (which is the total before the discount), and then another field in which I would calculate the discount, and then the new "Total" field that is the SubTotal - Discount.

In the Discount field, you can use something like this as your calculation script:

var subTotal = this.getField("SubTotal").value;

event.value = 0; // the default for this field

if (subTotal > 398.40) {

    event.value = (subTotal * 0.05).toFixed(2);

}

The script for "Total" would then be this:

event.value = this.getField("SubTotal").value - this.getField("Discount").value;

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
New Here ,
Jan 23, 2017 Jan 23, 2017

Can you help me understand which field to put this first calculation script?

  1. var subTotal = this.getField("SubTotal").value; 
  2.  
  3. event.value = 0; // the default for this field 
  4. if (subTotal > 398.40) { 
  5.     event.value = (subTotal * 0.05).toFixed(2); 

I have a field for:

total qty items

subtotal (qty*16.60)

and total (event.value = this.getField("SubTotal").value - this.getField("Discount").value;  )

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 ,
Jan 24, 2017 Jan 24, 2017
LATEST

As I said, this would be an additional field called "Discount". So in in addition to the "Total" and "SubTotal" fields you mention, you would need to add a third field called "Discount" and use the script from above.

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 ,
Jan 23, 2017 Jan 23, 2017

If you really want do this with just one Total field, use this:

event.value = Number(this.getField("Text1").value) + Number(this.getField("Text2").value) +

    Number(this.getField("Text3").value) + Number(this.getField("Text4").value); // keep on going until you have all your input fields

if (event.value >  398.40) {

    event.value = (event.value * 0.95).toFixed(2);

}

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