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

On Adobe XI Pro form tool how do I write a calculation such as excel formula =IFERROR(G14/C14,"")?

New Here ,
Feb 11, 2019 Feb 11, 2019

Copy link to clipboard

Copied

On Adobe XI Pro form tool how do I write a calculation such as excel formula =IFERROR(G14/C14,"")? When the form is blank the cell is not acting correctly with a return of zero ($0.00). Current simple field notation is PV1/OP with the return in a %.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

629

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
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Acrobat allows a programmer to adds JavaScript code to do calculation and verification.  To handle the specific case here you would use getField to read the value of C14, and make sure it isn’t zero before dividing by it.

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 ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

You can either check if the divisor is zero (or empty) first, or check if the result of the operation equals "Infinity" (no quotes). If that's the case, you know it was the result of division by zero, and then apply another value to it.

Keep in mind, though, that a percentage field can never be empty. Its default value is "0%", which is not always the correct result...

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
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Did anyone know that this is valid in simplified field notation:

A == 0 ? 0 : B / A

I was susprised, and cannot find a specification...

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 ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

No, it's not. You need to use a script.

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 ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

What would the script be?

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 ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Something like this:

var v1 = Number(this.getField("Field1").valueAsString);

var v2 = Number(this.getField("Field2").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

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 ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Thanks, that has gotten rid of the original issue yet caused another. The field for v1 is gotten by subtracting 1 field from another. Both of these fields are filled in by subtracting two other fields. I am trying to use this for an invoice adjustment sheet for everyone to be able to simply use and the math is done for them. I have the original sell (OS), new sell (NS) these two fields are entered by the company agent. Those two fields are auto-calculated to the invoice variance (IV) box. Then we have the agent enter in the original buy (OB) and the new buy (NB) and those auto-calculate to the buy variance box. The rest of the lines are auto-filled with simple math. original profit (OP) is OS-OB and new profit (NP) is NS-NB. Profit variance (PV2) is new profit - original profit (NP-OP). the last item is profit variance % (PV3). The script corrected the issue for PV3 getting an error when the sheet is blank, the issue now is when profit variance =$0.00  I get a warning "The value entered does not match the format of the field [PV2]" and then PV3 no longer returns a valid number when it should return 0.00% PV3=PV2/OP. Is what I want to do just too complicated for Adobe java to handle? Thanks for your help.

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 ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

LATEST

You need to apply the same logic to the other field, too. It's not too complicated for JS; It might be too complicated for someone without the required JS knowledge.

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
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

No, I'm saying it IS valid. I tried it in Acrobat X... like all simplified field notation, it compiles directly into JavaScript, and this looks valid to me.

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 ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Oh really? Wow... I'll try it myself.

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 ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

It does work, but the results are not really desired, I think... If both fields are empty the outcome is "NaN", and if A is empty but B is not (and not 0) the result is Infinity. I still think a script is the best way of doing it.

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
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

I think you're right. Could go further with

(A+0) == 0 ? 0 : (B+0) / (A+0) )

but it really isn't "simplified". Crucially, I think it would leave beginners more confused, not less...

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
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

The script would be written by a programmer. Would you like resources to learn how to program JavaScript?

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 ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Is there a good source of information on how to program javascript?

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