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

Conditional if/then doesn't clear when data in related field(s) is deleted.

Explorer ,
Nov 16, 2019 Nov 16, 2019

Copy link to clipboard

Copied

I have form of 12 rows, each with the following calculation in a field 'CD#Result' (the first two letters of the fields change per row).  "A" is a single field and "B" is a total of three other fields, that when compared to A determines what is in 'CD#Result'.  

 

It works almost perfectly.  However, I realized I have a problem if the user changes their mind.  If they make any entry in A or any of the three other fields and then delete those entries, the Result field does not clear.  I used the validation script to hide any 0 total in the 'CD#MoTotal' field to get a blank, but can't figure out how to do that in the Results field, or how to add to the calculation below.

 

What I want is that if both 'CD#Expect' and 'CD#MoTotal' are blank, then the 'CDResult' should be blank too.

TIA for your help!

 

var A = this.getField("CD#Expect").value; // Expected Activity for period reviewed;
var B = this.getField("CD#MoTotal").value; // Actual Activity for period reviewed;

if (B>A) {  event.value = "Exceeds";}
else if(B<A) {  event.value = "Under"; }
else if (B=A) {  event.value = "Meets";}

 

validate for 'CD#MoTotal':

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

TOPICS
Acrobat SDK and JavaScript

Views

279

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

Community Expert , Nov 18, 2019 Nov 18, 2019

Use this code:

 

var A = this.getField("CD#Expect").valueAsString; // Expected Activity for period reviewed;
var B = this.getField("CD#MoTotal").valueAsString; // Actual Activity for period reviewed;

if (A=="" && B=="") event.value = "";
else {
	A = Number(A);
	B = Number(B);
	if (B>A) event.value = "Exceeds";
	else if (B<A) event.value = "Under";
	else if (B==A) event.value = "Meets";
}

Likes

Translate

Translate
Community Expert ,
Nov 17, 2019 Nov 17, 2019

Copy link to clipboard

Copied

You have an error in your code.

Change this:

else if (B=A)

To:

else if (B==A)

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
Explorer ,
Nov 17, 2019 Nov 17, 2019

Copy link to clipboard

Copied

Hi Try67 - thanks for responding.  However, putting the double == in my formula didn't work the way I wanted.  Previously, using just the single = resulted in "Meets" when A and/or B had an entry and it met the condition.  If both the A & B were blank, it would say "Exceeds" as that is the first one listed  (I assume that is why).  When I changed it to == it kept the Meets even if both were blank. 

 

I found my answer in someone else's formula ........I kept the single =, but added another condition to the bottom of the calculation.................else event.value = "";

It was so simple, I'm mad at myself for not seeing it!  Now it works perfectly.

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 Expert ,
Nov 17, 2019 Nov 17, 2019

Copy link to clipboard

Copied

No, it didn't. The way you had it before the value of A was assigned to B, not compared with it.

However, since they were both identical in that scenario you didn't notice it, but it was still wrong.

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
Explorer ,
Nov 17, 2019 Nov 17, 2019

Copy link to clipboard

Copied

guess it "working" is a fluke....so how do I get this to happen?

if A and B are numbers and match then "Meets"

if A and B are not a number (blank) then return a blank

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 Expert ,
Nov 18, 2019 Nov 18, 2019

Copy link to clipboard

Copied

What about if A is blank and B is not? Or the other way around?

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
Explorer ,
Nov 18, 2019 Nov 18, 2019

Copy link to clipboard

Copied

Thats ok if one is blank.  Could be that A (Expected) has a number entry but B (Actual) had no activity during the period (or visa versa).  In that case the blank should be treated as a zero.  But if both A and B are blank, then result should also be blank.  Currently Result field remains a blank unless user inputs data in any of the related fields.  Once data is entered, even if deleted, the Result field retains the "Meets" criteria.  Does that make sense?

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 Expert ,
Nov 18, 2019 Nov 18, 2019

Copy link to clipboard

Copied

Use this code:

 

var A = this.getField("CD#Expect").valueAsString; // Expected Activity for period reviewed;
var B = this.getField("CD#MoTotal").valueAsString; // Actual Activity for period reviewed;

if (A=="" && B=="") event.value = "";
else {
	A = Number(A);
	B = Number(B);
	if (B>A) event.value = "Exceeds";
	else if (B<A) event.value = "Under";
	else if (B==A) event.value = "Meets";
}

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
Explorer ,
Nov 18, 2019 Nov 18, 2019

Copy link to clipboard

Copied

LATEST

Wow!  Thank you so much!!!.  Happy to have the correct formula rather than one that works at the moment, but may not under future/other circumstances!  Will certainly save this message for future forms that I am converting from Word templates to PDF form.  You Rock!

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