These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Discount Calculation Script

KDCS
Registered: Sep 30 2009
Posts: 36
Answered

Hello,
I have an XFA form build in LCD 8.2 that I am looking for a script to calculate the following:

If the price is between $200 and $500, then a discount of 5% is applied to the price and shows up in a discounted price field.
So, if the price is $200 the actual price will be $190.

There would be variable price points where different discounts apply.

Can someone help?

Thanks in advance.

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Well, this can be done easily.

Put this script into the calulate event of the discountered price field.
You have to change "NumericField1" to the name of the field where you type in your prices.

And don't forget to set the script editor to FormCalc, not JavaScript.

var MyPrice = NumericField1.rawValue if (MyPrice >= "200" and MyPrice <= "500" ) then$.rawValue = MyPrice * 0.95 ;5% discountelse$.rawValue = MyPrice ;no discountendif

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

KDCS
Registered: Sep 30 2009
Posts: 36
Thank you Radzmar.

It works, but only with whole numbers. Is there a way to change the script to use decimal points. Say if the total is $200.25 I would still get the discounted price? As it works now, if the value is $200.25 I do not get the discount. The Price comes out $200.25.

Thanks again.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
I would use a decimal field and not put the numeric values in quotes, making them character strings and not numeric values.

//FormCalc to compute discounted pricevar MyPrice = DecimalField1.rawValue if (MyPrice >= 200 and MyPrice <= 500 ) then$.rawValue = MyPrice * 0.95; // 5% discountelse$.rawValue = MyPrice ; // no discountendif

And also look at your 'Display Pattern' to make sure it will allow for the display of decimal values.

When you enter 200.75 does the price roundup? Then you need to change your display pattern.

George Kaiser

KDCS
Registered: Sep 30 2009
Posts: 36
gkaiseril,

Thank you. That works perfectly. I appreciate all the great advice on this website.