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

SOS / Java Script for Adobe Acrobat - Custom Script

Community Beginner ,
Oct 25, 2021 Oct 25, 2021

Hi there! 
Am trying to use the "Custom Calculation Script" to calculate a percentage off a final sale for the "Amount Due" field. For example, if the total is $100 and I grant 25% off, I want the Amount Due to show as that. 

TOPICS
Acrobat SDK and JavaScript
1.9K
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

correct answers 2 Correct answers

Community Beginner , Oct 27, 2021 Oct 27, 2021

event.value = this.getField ("A").value - ( this.getField("A").value * this.getField("B").value )

Translate
Community Beginner , Oct 27, 2021 Oct 27, 2021

For anyone interested, attached is the working file. 

Translate
Community Beginner ,
Oct 25, 2021 Oct 25, 2021

Subtotal = "A"

Discount = "B"

Screenshot 2021-10-25 173207.pngexpand image

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 ,
Oct 25, 2021 Oct 25, 2021

Try this:

var s = Number(this.getField("A").value);
var p = Number(this.getField("B").value);
if(p == 0)
event.value = s;
else
event.value = s*(1-p);

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 ,
Oct 27, 2021 Oct 27, 2021

I was able to figure it out! Very simple solution actually.
For anyone interested, the equation I used was this: 

 

event.value = this.getField ("A").value - ( this.getField("A").value * this.getField("B").value )

 

whereas

A = Subtotal

B = Discount Amount 

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 ,
Oct 27, 2021 Oct 27, 2021

event.value = this.getField ("A").value - ( this.getField("A").value * this.getField("B").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 Beginner ,
Oct 27, 2021 Oct 27, 2021

For anyone interested, attached is the working file. 

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 ,
Oct 27, 2021 Oct 27, 2021
LATEST

You don't need a script for this calculation.

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