Copy link to clipboard
Copied
Bear with me as I try to explain this as simply as possible.
I need to do a calculation where the price is calculated, factoring in a minimum data point and pricing.
FieldA = amount of item
FieldB = cost based on the number of items
Pricing = minimum charge $245 for up to 3500 items; 0.085 per item thereafter
Right now I have:
FieldB simplified notation: (245+((FieldA-3500)*0.085))
FieldB custom validation: if(event.value == 0 | event.value =='') event.value = ''; else if(event.value <= 245) event.value = 245;
That might be a dumb way of doing it, but it works. Anything in FieldA put in as 3500 or below returns $245. Making it 3501 and above starts increasing the price.
My main issue, and the one I can't solve myself, is that with the above notation, it defaults FieldB to $245 even if no item amount is in FieldA. Is there some sort of code I can use that is basically 'if FieldA is empty or 0, then FieldB should also be empty?
++EDITED REPLY, added missing parenthesis in the declared variable numberOfItems as noted by @Nesa Nurani
Hi @scrabbleship13 ,
There are syntax errors and inconsistencies with your current method.
You may work around this formula in different other ways using Acrobat JavaScript.
In my script below, for example, I am employing a custom calculation script and it is run in FieldB:
var numberOfItems = Number(this.getField("FieldA").value);
var minimumPricing = 245;
var extraCharge =
...
Copy link to clipboard
Copied
++EDITED REPLY, added missing parenthesis in the declared variable numberOfItems as noted by @Nesa Nurani
Hi @scrabbleship13 ,
There are syntax errors and inconsistencies with your current method.
You may work around this formula in different other ways using Acrobat JavaScript.
In my script below, for example, I am employing a custom calculation script and it is run in FieldB:
var numberOfItems = Number(this.getField("FieldA").value);
var minimumPricing = 245;
var extraCharge = 0.085;
if(numberOfItems =="") {
event.value = "";
} else {
if(numberOfItems !=="") {
if(numberOfItems >= 1 && numberOfItems <= 3500) {
event.value = minimumPricing;
} else {
event.value = minimumPricing + (minimumPricing * extraCharge);
}
}
}
Copy link to clipboard
Copied
This works fantastically. Thank you so much!!
Copy link to clipboard
Copied
You're welcome.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You can use this at validation:
var price = Number(this.getField("FieldA").valueAsString);
if(!price)event.value = "";
else if(price && Number(event.value) < 245)event.value = 245;
You are missing parentheses in line 1.
Also, your script will not work:
event.value = minimumPricing + (minimumPricing * extraCharge);
you are just calculating 245+(245*0.085) which will get you a result of 265.83, you need to replace second 245 with number of items that are above 3500 like OP did in her SFN.
Copy link to clipboard
Copied
Thank you @Nesa Nurani I edited the reply to reflect that change.
I am clear with handling the 0 value or "" empty string value. But I wasn't sure if the OP actually wants to also reflect the actual extra charge when the value entered in FieldA is above or equal to 3501.
So, I abandoned the appetite for the Simplfied Field Notation (SFN) equation in combination with a validation script because the OP also mentioned this other intent:
"Anything in FieldA put in as 3500 or below returns $245. Making it 3501 and above starts increasing the price"
Doing a SFN like that in combination with a validation script will only show $245 in FieldB consistently, while entering a value higher or equal to 3501 in FieldA will do nothing else with the validation script; it wasn't working for me.
Since the OP also didn't clarified if "Pricing" is an actual text field (where it populates the total pricing with the extra charge factored in when a value that is greater or equal to 3501 is entered in Field A), maybe the OP can jump in and clarify his/her desired full intent.
Copy link to clipboard
Copied
I think you are absolutely correct though. The SFN with a validation script is working for me now.
Copy link to clipboard
Copied
And thank you for your assistance also!