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

SOS / Java Script for Adobe Acrobat - Custom Script

Community Beginner ,
Oct 25, 2021 Oct 25, 2021

Copy link to clipboard

Copied

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

Views

1.6K

Translate

Translate

Report

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 )

Votes

Translate

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

For anyone interested, attached is the working file. 

Votes

Translate

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

Copy link to clipboard

Copied

Subtotal = "A"

Discount = "B"

Screenshot 2021-10-25 173207.png

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

For anyone interested, attached is the working file. 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

You don't need a script for this calculation.

Votes

Translate

Translate

Report

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