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.


Converting if statement in excel to work in a PDF formula

New Here ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

Good afternoon

I have been reading a lot of questions and answers on this forum for converting an Excel IF formula into a formula that will work in a PDF. I have been unable to find any that work with my case and I don't understand enough of what people are saying to figure it out on my own. Can someone please help? The current formula is set up like this:

=IF(D31="Y",750,0)*12+(D35+600*12)

I have different references for D31 and D35 in my PDF document which are as follows:

D31 - Vehicle

D35 - PorterVehicles

Any help in the right direction would be so appreciated. Thank you!

TOPICS
Acrobat SDK and JavaScript, Windows

Views

109

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 , Apr 09, 2019 Apr 09, 2019
Well actually the "if" statement is working since things are changing when a Y is entered. It's the calculation that has the issue. I don't know why the value is jumping so much. I'd have to see your document to figure out the exact problem, but try this. var nValue = Number(this.getField("PorterVehicles").value + 600*12);if(this.getField("Vehicle").value == "Y")  nValue += 9000;event.value = nValue;I suspect that in the first line the value is being interpreted as a string.

Likes

Translate

Translate
Adobe Community Professional ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

Here's an article on writing an "if":

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

Explain the condition you want and we can provide some sample code.

For example: "If the Vehicle field is "Y" then the calculation in the "Result field" adds 750 to the calculated value.

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 ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

I did look at this article earlier from another forum post and was really confused...I think it hard for me to follow where I plug in my values to achieve the result needed.

The formula is asking that if the Vehicle field is is Y, then it adds 750*12 to the calculated value. If the Vehicle Field is N (or other letter) then it would just be the calculated value.

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 ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

Here is a custom calculation script

event.value = this.getField("PorterVehicles").value + 600*12

if(this.getField("Vehicle").value == "Y")

  event.value += 750*12;

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 ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

So close! It works perfectly when the value is not Y. When I change it to Y the value jumps up by about 72 million instead of 9,000.

I really really appreciate your help. It is definitely helping me see how to do this for other formulas that I have moving forward.

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 ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

Well actually the "if" statement is working since things are changing when a Y is entered. It's the calculation that has the issue. I don't know why the value is jumping so much. I'd have to see your document to figure out the exact problem, but try this.

var nValue = Number(this.getField("PorterVehicles").value + 600*12);

if(this.getField("Vehicle").value == "Y")

  nValue += 9000;

event.value = nValue;

I suspect that in the first line the value is being interpreted as a string.

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 ,
Apr 10, 2019 Apr 10, 2019

Copy link to clipboard

Copied

LATEST

That worked! Thank you so much for all your help! I have another one in the same document to do, but now that I can see the structure as it applies to my document, I think I can figure it out! Thank you again!

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