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

Help with null vs 0s Adobe Form Issue

New Here ,
Nov 19, 2018 Nov 19, 2018

I have 3 calculated fields.

Field1: sum of 5 values at timepoint1

Field 2: sum of 5  values at timepoint 2

Field 3: based on Field1 and Field2 sums ( it's a % change) --- (sum2-sum1)/sum1

The problem is this:

Field 2 is defaulting at 0 before anyone enters a 0. It should be null until a value is entered. Valid values can be 0,1,2,3,4 etc. anything greater or equal to 0.

Field 3 is then calculating before Field 2 has a valid entered value - because of the default 0 for Field2. I need it to calculate when an actual >=0 value is entered for field2.

How can I do this? I've tried so many options - the typical event.value==0 et.et. But i need to figure out with my limited javascripting how to ....any help will be awesome.

Example below:

the 10= FIELD1

Field 2: Diameter (mm) value = 0 because nothing is entered in the rows above - see all NULLS

Field 3: From BASELINE = -100 because its' calculating percent change from (0-10/10)  *100 = -100. I need the 0 only to be calculated if that sum really is 0 vs null as it is now

TOPICS
PDF forms
2.3K
Translate
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 ,
Nov 19, 2018 Nov 19, 2018

How did you set up the calculation? If you used a script, post it, please.

Translate
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 ,
Nov 20, 2018 Nov 20, 2018

Ok thanks: Here are my calculations

Field1: diameter baseline sum : sum function in the text field properties

I also have this in the validate :

   // null filed value if entry is zero

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

Field2:

Diameter 2 --- sum function in text field  ( where the sum default is 0)

with this in validate:

   // null filed value if entry is zero

     if(event.value == 0) event.value = 0

Field 3:

% change from baseline ( the one with the -100 when no field2 is entered but hte default is 0)

in calculate:

var baseDiaSum = this.getField("BASEDIAMETERSUM1").value;

var Dia2 = this.getField("DIAMETERSUM2").value;

if((!baseDiaSum) || (baseDiaSum == 0) ){

event.value = 0;

}

else{

event.value = ((Dia2 - baseDiaSum)/baseDiaSum)*100

}

in validate i was playing around with it and put this for now:

   // null filed value if entry is zero

     if(event.value ==0) event.value = "n/a";

Translate
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 ,
Nov 20, 2018 Nov 20, 2018

Can you share the actual file (using Dropbox, Google Drive, Adobe Cloud, etc.)?

Translate
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 ,
Nov 20, 2018 Nov 20, 2018
Translate
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 ,
Nov 20, 2018 Nov 20, 2018

The "-100" result is correct for the values you entered. If Dia2 is 0 and baseDiaSum is 10 then the formula is:

((0 - 100)/100)*100 = -100

If you don't want it to produce that result then you need to define how it should behave in this situation. For example, you can add a condition that if Dia2 is 0 then the result is 0, no matter what, like you did with baseDiaSum.

Translate
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 ,
Nov 20, 2018 Nov 20, 2018

CORRECT, it is if the value really is 0 , but the value shouldnt be 0 for field2. it should be NULL - until the user actually enters 0 for hte fields above that are summed. I know that adobe sees that as '0' but i need that to be NULL until the user actually inputs a 0...

understand? They didnt. THats automatic

Translate
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 ,
Nov 20, 2018 Nov 20, 2018

A null value if accessed as a number is null or zero. If you want to alter the behavior then you will need to do some custom scripting for the format of the field. You need to test the event value for the null value of "", an empty string and then set the value to an empty string.

Using the "Field is the ____ of the following fields" or the simplified field notation assumes the result will be a numeric value and not a string value. You can override this bu using the custom format option on the "Format" tab. Note, using custom JavaScript calculation option also does this but the programmer can force the value of the field to the null string value.

Translate
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 ,
Nov 20, 2018 Nov 20, 2018

As I said, you need to check if that field is empty, just like you do with the other one.

Translate
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 ,
Nov 20, 2018 Nov 20, 2018

@try67 thanks for assisting thus far, what do you mean check if empty like the other one? Which field?

Translate
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 ,
Nov 20, 2018 Nov 20, 2018
LATEST

Like this:

var Dia2 = this.getField("DIAMETERSUM2").valueAsString;

if (Dia2=="") event.value = "";

else {

     // place rest of calculation code here

}

Translate
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