Skip to main content
Inspiring
Apr 7, 2020 12:18 AM UTC
Question

Lost in Calculations???

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 is closed to new replies. Start a new post to keep the conversation going.

8 replies

ls_rbls
Community Expert
Community Expert
Apr 7, 2020 12:59 AM UTC

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);

 

Translate
Technical Generalist
Inspiring
Apr 7, 2020 1:38 AM UTC

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. 

 

 

Translate
ls_rbls
Community Expert
Community Expert
Apr 7, 2020 2:46 AM UTC

 

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).

 

 

Translate
Technical Generalist