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

Color of a text field based on whether the calculations of three other fields are equal.

Explorer ,
Mar 29, 2023 Mar 29, 2023

I can't seem to figure out how to do this. I would like my "Totals" title text field to turn from red to green if the three subtotaled fields underneath it all contain the same calculated number. I already have the calculations in the three transparent boxes. 

Totals Boxes.jpg

The script I was able to piece together from my limited background knowledge and other resources is below.  

 

var t1 = Number(this.getField("SchoolDayMinutes").valueAsString);
if(event.value && t1)
var t2 = Number(this.getField("ScheduledPlusPassPer").valueAsString);
if(event.value && t2)
var t3 = Number(this.getField("ScheduleSummary").valueAsString);
if(event.value && t3)
event.target.fillColor = t1 = t2 = t3 == event.value ? color.green : color.red;

 

Thank you

 

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF forms
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 ,
Mar 29, 2023 Mar 29, 2023

Try this:

var t1 = Number(this.getField("SchoolDayMinutes").valueAsString);
var t2 = Number(this.getField("ScheduledPlusPassPer").valueAsString);
var t3 = Number(this.getField("ScheduleSummary").valueAsString);
if(t1&&t2&&t3){
if(t1 == t2 && t2 == t3)
event.target.fillColor = color.green;
else
event.target.fillColor = color.red;}
else
event.target.fillColor = color.red;

 

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 ,
Mar 29, 2023 Mar 29, 2023

Try this:

var t1 = Number(this.getField("SchoolDayMinutes").valueAsString);
var t2 = Number(this.getField("ScheduledPlusPassPer").valueAsString);
var t3 = Number(this.getField("ScheduleSummary").valueAsString);
if(t1&&t2&&t3){
if(t1 == t2 && t2 == t3)
event.target.fillColor = color.green;
else
event.target.fillColor = color.red;}
else
event.target.fillColor = color.red;

 

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 ,
Mar 29, 2023 Mar 29, 2023

It works, but if one of the numbers that is part of a calculation field changes, it doesn't turn red again. For example, if someone changes an early entry that makes the Schedule Summary = 590 and the other two subtotal fields are = 600, the "Totals" field remains green. Is there a way to make the "Totals" field update if there are any changes?

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 ,
Mar 29, 2023 Mar 29, 2023

That shouldn't happen. 

If other fields are calculated check if field calculation order is correct. 

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 ,
Mar 29, 2023 Mar 29, 2023

I just checked the calculation order and it appears that I have a lot of work ahead. I have a lot of fields to calculate. I know how to use the menu and click them up and down, but is there a quicker way you can suggest? I also need to do a cusom tab order. Any suggestions on how to do these two tasks quickly would be greatly appreciated. Thank you. 

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 ,
Mar 29, 2023 Mar 29, 2023

You can't change tab order with a script.

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 ,
Apr 10, 2023 Apr 10, 2023
LATEST

Thank you for all your help. 

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