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

Formula validation and calculation for pricing with minimums

Community Beginner ,
Mar 10, 2023 Mar 10, 2023

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?

TOPICS
PDF forms

Views

1.3K

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 1 Correct answer

Community Expert , Mar 10, 2023 Mar 10, 2023

++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 = 
...

Votes

Translate

Translate
Community Expert ,
Mar 10, 2023 Mar 10, 2023

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

    }
  }
}

 

 

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 ,
Mar 13, 2023 Mar 13, 2023

Copy link to clipboard

Copied

This works fantastically. Thank you so much!!

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 ,
Mar 13, 2023 Mar 13, 2023

Copy link to clipboard

Copied

You're welcome.

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
New Here ,
Mar 13, 2023 Mar 13, 2023

Copy link to clipboard

Copied

LATEST
Google





Sanja S


Sanja S

Делим место са вама


Wurster Webstube


Wurster Webstube

Wremer Str. 140, 27639 Wurster Nordseeküste, Њемачка

+49 4705 752






Прикажи на Google мапама




Google

© 2018 Google LLC 1600 Amphitheatre Parkway, Mountain View, CA 94043

Послао је корисник Sanja S преко Google мапа

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 ,
Mar 10, 2023 Mar 10, 2023

Copy link to clipboard

Copied

@scrabbleship13 

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;

 

@ls_rbls 

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.

 

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 ,
Mar 11, 2023 Mar 11, 2023

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.

 

 

 

 

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 ,
Mar 11, 2023 Mar 11, 2023

Copy link to clipboard

Copied

I think you are absolutely correct though. The SFN with a validation script is working for me now.

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 ,
Mar 13, 2023 Mar 13, 2023

Copy link to clipboard

Copied

And thank you for your assistance also!

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