Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Confused about If Then Statements

Community Beginner ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

I'm converting a Projected Operating Costs spreadsheet from Excel to Adobe since some of my end users do not have Excel and Google takes away the security features in the document.

 

I have no experiencing with Java and am really struggling grasping how to write an if then statement for one of the fields.

 

The Text field needs to look at another field "S2HRFreeCount" and determine if it is greater than '0'.  If it is greater than '0' I want it to display the value I have entered in another field "S2HRFreeRate."  This rate changes every year so I'm wanting to use it from the field rather then enter the value in the script.  Less places to update.  If  there is no text in "S2HRFreeCount" than I want the field to either be blank or display "0."

 

My end user does not need to enter a value in field S2HRFreeCount. 

 

Any assistance would be appreciated.  I've only started creating Adobe Fillable Forms within the last 6 months so I'm learning as I go.  And this is the most complicated component so far.

TOPICS
Edit and convert PDFs, PDF forms

Views

132

Likes

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

Adobe Community Professional , Oct 15, 2020 Oct 15, 2020
The easiest way to do this is a Custom Calculation script on the text field.  var cFreeCount = this.getField("S2HRFreeCount").valueAsString; if((cFreeCount != "") && !isNaN(cFreeCount) && (Number(cFreeCount) > 0)) event.value = this.getField("S2HRFreeRate").value; else event.value = ""; Note that there are 3 conditions used to determine whether or not the FreeRate value is used.  The FreeCount field is not empty, it's value is a number, and that number is greater than 0; You can r...

Likes

Translate

Translate
Adobe Community Professional ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

The easiest way to do this is a Custom Calculation script on the text field. 

 

 

var cFreeCount = this.getField("S2HRFreeCount").valueAsString;
if((cFreeCount != "") && !isNaN(cFreeCount) && (Number(cFreeCount) > 0))
  event.value = this.getField("S2HRFreeRate").value;
else
  event.value = "";

 

 

Note that there are 3 conditions used to determine whether or not the FreeRate value is used. 

The FreeCount field is not empty, it's value is a number, and that number is greater than 0;

 

You can read more about calculation scripts here:

https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm

And about if statements in calculations here:

https://acrobatusers.com/tutorials/conditional-execution/

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

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 16, 2020 Oct 16, 2020

Copy link to clipboard

Copied

Thank you.  I have so much more to learn about these advance features in Adobe.  But making the conversion to Adobe will make my life so much easier in the long run.

Likes

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 ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

I am stuggling to get this working.

 

( BldgPermitFee+ElectFee+PlumbingFee+SignFee+COO )= < 10,000 than *.2

( BldgPermitFee+ElectFee+PlumbingFee+SignFee+COO )= between 10,001 - 20,000 than *.12

( BldgPermitFee+ElectFee+PlumbingFee+SignFee+COO )= between 20,001 - 30,000 than *.10

( BldgPermitFee+ElectFee+PlumbingFee+SignFee+COO )= between 30,001 - 40,000 than *.09

( BldgPermitFee+ElectFee+PlumbingFee+SignFee+COO )= > 40,000 than *.08

Likes

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
Adobe Community Professional ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Is this a custom calculation script?  I'll just assume it is for the answer. 

First, you have to actually have an if/then structure and use Acrobat JavaScript functions.

I'd suggest reading these articles:

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

https://acrobatusers.com/tutorials/conditional-execution/ 

 

Here's how you set it up.  The important bit for a calculation is that the calculated value is assigned to "event.value".

 

 

 

var nSum = this.getField("BldgPermitFee").value + this.getField("ElectFee").value + this.getField("PlumbingFee").value + this.getField("SignFee").value + this.getField("COO").value;

if(nSum <= 10000)
   event.value = 0.2;
else if (nSum <= 20000)
   event.value = 0.12;
...etc...

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

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 ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Thank you I did find one mistake I keep doing but its still not working and i have read the artcles and made changes.  It there something else I could be missing?

Likes

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
Adobe Community Professional ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Well, the question is - "What's not working". This is the first part of figuring out whats wrong. What values appear in the text box when you enter data? Are any errors reoported in the Console Window? Did you fill out the rest of the "if" block? I only provided the first two cases as a sample of how it should be done.  Are all the field names correct? 

 

Post the exact script you are using. We can't tell you anything without information. 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

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 ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

var nSum = this.getField("BldgPermitFee").value + this.getField("ElectFee").value + this.getField("PlumbingFee").value + this.getField("SignFee").value + this.getField("COO").value;

if(nSum <= 10000) event.value * 0.2; else if (nSum <= 20000) event.value * 0.12; else if (nSum <= 30000) event.value *.10; else if (nSum <= 40000) event.value *.09; else if (nSum > 40000) event.value * .08

 

The values are not appearing in the box. it just says 0.

 

Everything for the fields is correct compared to my form.

 

Thank you so much I have been reading articles and could not get it.

Likes

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
Adobe Community Professional ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

The result of any calculation must be placed in "event.value". 

That is why the code I provided uses the "=" symbol, For example: event.value = 0.2;

 

The result you want is not clear from your post. Did you want the field value to be the "sum" times the decimal value? If so, then use code like this:  event.value = nSum * 0.2;

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

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 ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

boa tarde! meu gmail nao para de receber mail de voces!e nao consigo
cancalar , podem me ajudar?

Likes

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
Adobe Community Professional ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

LATEST

There's an unsubscribe link at the bottom of each email you're getting from this forum.

Likes

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