PDF Form - Display text conditionally based on lowest value of four boxes.

Community Beginner ,
Jun 27, 2022 Jun 27, 2022

Copy link to clipboard

Copied

I have a PDF form that calculates 4 fields in a table from other data in the form. It works great using Simplified Field Notation.

 

I would like to display the column title of the lowest of the four fields in a cell below. See the table below as an example:

 DBBDBC+DBBC+DB
Total Ranking Score30020010050
     
Recommended MethodC+DB   

 

I can do this in excel using this formula: =INDEX(B1:E1,0,MATCH(MIN(B2:E2),B2:G2,0)). 

 

My question is how to do this in a excel form. Is there a javascript custom calculation script that I can use or some way to display text conditionally in a pdf?

 

Thank you in advance for your help!

TOPICS
JavaScript , PDF forms

Views

56

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

Adobe Community Professional , Jun 28, 2022 Jun 28, 2022

I don't know about excel, but yes, there is a way to do this in a PDF form. Actually there are several. 

 

Here's how I would implement the functionality.

1. Name the 4 ranking score fields using a group naming prefix. This allows you to create a generic solution that can be easily expanded in the future, or reused for another purpose.  Something like "RankingScore.total1", "RankingScore.total2", etc.

 

2. Put the  "Recomended Method" text you want displayed in the tooltip of the associated Rank

...

Likes

Translate

Translate
Adobe Community Professional ,
Jun 28, 2022 Jun 28, 2022

Copy link to clipboard

Copied

I don't know about excel, but yes, there is a way to do this in a PDF form. Actually there are several. 

 

Here's how I would implement the functionality.

1. Name the 4 ranking score fields using a group naming prefix. This allows you to create a generic solution that can be easily expanded in the future, or reused for another purpose.  Something like "RankingScore.total1", "RankingScore.total2", etc.

 

2. Put the  "Recomended Method" text you want displayed in the tooltip of the associated Ranking Score field. So now the field and the display text are together. 

 

3. Create a calculation script in the  "Recomended Method" field to analyze the "RankingScore" fields to find the lowest value and select the associated text. 

 

Here's the script

var oMinFld = null;
// This line gets all the fields in the "RankingScore" group and
// finds the one with the lowest value. It assumes all fields contain a valid value 
this.getField("RankingScore").getArray().forEach(
      function(oFld)
      {
         if(!oMinFld || (oFld.value < oMinFld.value))
              oMinFld = oFld;
      }
);
if(oMinFld)
   event.value = oMinFld.userName; // this is the tooltip
else
   event.value = "";
 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
Jun 28, 2022 Jun 28, 2022

Copy link to clipboard

Copied

That worked absolutely perfect. Thank you, THANK YOU!.

 

I have another post using the same table here but needed to color the background based on lowest to highest. Would you be able to help with that one too?
https://community.adobe.com/t5/acrobat-discussions/format-pdf-form-fields-based-on-lowest-to-highest...

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 Beginner ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

LATEST

Is there a way to have it set so that the Recommended Method field is blank until the calculations are run?
Currently it is just showing the first tooltip (or actually the last tooltip that was in the box) because the default values are 0 until the fields above it are filled in. I have tried to change up the code but can't get it to work. This is my best effort:

if (oMinFld === 0)
   event.value = "";  
else
   event.value = oMinFld.userName; // this is the tooltip

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