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

If Text Box 1 is <$10,000 and/or Text Box 2 is <10 Years Old, Text Box 3 Needs to Populate "Yes"

Explorer ,
Jul 29, 2024 Jul 29, 2024

Good morning!

 

I have a PDF I am working on that has a section with 3 text boxes. Text Box 1 is current balance in currency. Text Box 2 is Model Year. Text Box 3 the user types "yes/no". What I am needing is Text Box 3 to auto-populate with "Yes" or "No" based off Text Box 1 and 2. If Text Box 1 is less than $10,000, Text Box 3 needs to auto populate "yes". If Text Box 2 is less than 10 years old(from the year populated in Text box 2), Text Box 3 needs to auto populate "yes". If Text Boxes 1 and 2 are both less than $10,000 and less than 10 years old, Text Box 3 needs to auto populate "yes". If neither Text Box 1 or 2 are less than $10,000 or less than 10 years old, Text Box 3 needs to auto populate 'No"

 

Thanks for the help!!

TOPICS
How to , PDF
1.1K
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
1 ACCEPTED SOLUTION
Community Expert ,
Jul 29, 2024 Jul 29, 2024

Ah, I thought the second field contains an age, not a year. That complicates things a bit... Try this:

 

var v1 = this.getField("Text Box 1").valueAsString;
var v2 = this.getField("Text Box 2").valueAsString;
if (v1=="" || v2=="") event.value = "No";
else {
	if (Number(v1)<10000 || (new Date().getFullYear()-Number(v2))<10) event.value = "Yes";
	else event.value = "No";
}

 

Just be aware this won't update automatically when you open the file. So if you enter "2015" now it will show "Yes", but won't change by itself to "No" if you open the file next year. You will need to force a recalculation to do that. One way is to add the following command as a doc-level script:

 

this.calculateNow();

 

 

View solution in original post

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 ,
Jul 29, 2024 Jul 29, 2024

What should happen if either of those fields is empty?

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
Explorer ,
Jul 29, 2024 Jul 29, 2024

@try67 They shouldn't ever be empty, but if they are, Text Box 3 should say "No"

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 ,
Jul 29, 2024 Jul 29, 2024

They can always be, and you have to take it into account.

Try this code as the custom calculation script for Text Box 3:

 

var v1 = this.getField("Text Box 1").valueAsString;
var v2 = this.getField("Text Box 2").valueAsString;
if (v1=="" || v2=="") event.value = "No";
else {
	if (Number(v1)<10000 || Number(v2)<10) event.value = "Yes";
	else event.value = "No";
}
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
Explorer ,
Jul 29, 2024 Jul 29, 2024

@try67 It works perfectly except if Text Box 2 (Model Year) is < 10 years old and Text Box 1 (Current Balance) is >$10,000 it populates "No" for Text Box 3 (10/10 Rule Check) when it should be "Yes".  So if the Balance and/or the Model year is <$10,000/10 years old, Text Box 3 (10/10 Rule Check) should say "Yes"

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 ,
Jul 29, 2024 Jul 29, 2024

Ah, I thought the second field contains an age, not a year. That complicates things a bit... Try this:

 

var v1 = this.getField("Text Box 1").valueAsString;
var v2 = this.getField("Text Box 2").valueAsString;
if (v1=="" || v2=="") event.value = "No";
else {
	if (Number(v1)<10000 || (new Date().getFullYear()-Number(v2))<10) event.value = "Yes";
	else event.value = "No";
}

 

Just be aware this won't update automatically when you open the file. So if you enter "2015" now it will show "Yes", but won't change by itself to "No" if you open the file next year. You will need to force a recalculation to do that. One way is to add the following command as a doc-level script:

 

this.calculateNow();

 

 

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
Explorer ,
Jul 29, 2024 Jul 29, 2024

@try67  Hmmm it still seems to be showing Text Box 3 (1010 Rule Check) as "No" when Text Box 2 is <10 years old.

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 ,
Jul 29, 2024 Jul 29, 2024

2024 - 2004 is not < 10

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
Explorer ,
Jul 29, 2024 Jul 29, 2024

@Bernd Alheit @try67  AAhhhhhh my apologies! It needs to be >10 years

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 ,
Jul 29, 2024 Jul 29, 2024
LATEST

Just change the < operator in that part of the code to > , then.

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