Skip to main content
Inspiring
April 7, 2020
Question

Lost in Calculations???

  • April 7, 2020
  • 1 reply
  • 1120 views

Ok. Could someone please help? I've been tasked with taking an excel order from and creating a fillable PDF. Here is where I lose it. I need to create a calculation with user filled amounts that calculate sum and a discount.

Subtotal + Misc Amount + Shipping Costs = Final Total
Discount in percentage will applied to final total.

The calcualtion for the final total I get if there is no discount. The discount is a user filled field that may or may not apply.
If there no discount then the field need to be empty. If the user inputs a number then it must show a whole number with the percentage sign and calculates the final total.

Any help would be great. I'm a scripting noob.

This topic has been closed for replies.

1 reply

ls_rbls
Community Expert
Community Expert
April 7, 2020

Hi,

 


Rightclick on the "Discount Amt" field and go to the Format tab, then click on "Edit" in the Custom Format Script section.

 

You can use a line of code like this as the custom format script:

 

if(!event.willCommit)
console.println(!event.value);

{
var v = +getField("Discount Amt").value;

event.value = v/100;
if(v=="") event.value ="";
}

 

 

In the Final Total field, right-click to select Properties and goto the "Calculate" tab. Tick the radio button below "Custom calculation script" and you may add something like this:

 

 

var a = this.getField("Subtotal").value+ this.getField("Misc. Amount").value+this.getField("Shipping Costs").value;
var b = this.getField("Discount Amt").value;
if (b =="") event.value =a;
else if(b !="") event.value = a+(a/b);

 

Inspiring
April 7, 2020

Hi ls_rbls,

 

It isn't quite working. It's adding to the final total rather than applying the discount.
Also I need to show the discount amount as a whole number. Ex. 10% rather than 0.1. 

 

 

ls_rbls
Community Expert
Community Expert
April 7, 2020

 

My apologies, I made a mistake.

 

In the last line of the code above:

 

else if(b !="") event.value = a+(a/b);

 

Change the last part to  a-(a/b).