Skip to main content
Participating Frequently
June 26, 2023
Frage

Converting IF Then statement from excel to PDF form

  • June 26, 2023
  • 1 Antwort
  • 2403 Ansichten

I have the statement IF(A>0, A-B, B) in a excel document that I need to use in a PDF form and do not know how to write the script. Any help would be greatly appreciated, thanks!

Dieses Thema wurde für Antworten geschlossen.

1 Antwort

Nesa Nurani
Community Expert
Community Expert
June 26, 2023

Try something like this:

var a = Number(this.getField("A").valueAsString);
var b = Number(this.getField("B").valueAsString);

if(a&&b){
if(a>0)
event.value = a-b;
else
event.value = b;}
else
event.value = 0;

 

try67
Community Expert
Community Expert
June 26, 2023

This will not work correctly, as (a&&b) will always return false if either one of them is zero. So if A is 0 and B is 5 the result will be 0, not 5 (as expected).
If you want to check that neither of the fields are empty then you need to check their values as strings, and only then convert them to numbers.

try67
Community Expert
Community Expert
June 26, 2023

Thank you. That seems to have fixed the issue when A=0 but when I try that and I imput a value A=10 and B=2 the calculation comes out as 0 now instead of 8. 


Works fine for me... See attached.

If your A and/or B fields have a calculated value, check the fields' calculation order.

Also, make sure remove all previous actions you added.