Skip to main content
Participant
October 21, 2022
Question

Compare field data then ranking it

  • October 21, 2022
  • 2 replies
  • 235 views

Hi,

I'm trying to look for a script that compare multiple field data, then generate a rank number based on those data in an empty field. Any help would be greatly appreciates.

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
October 21, 2022

Lets say that the ranked fields are named "Rank.A", "Rank.B", etc. And the result field is named "Result".

This one line BUTTON script will return a comma separated list of field names sorted with the highest field value number first and the lowest field value number last.

 

this.getField("Result").value = this.getField("Rank").getArray().map(a=> x={name:a.name.split(".").pop(), value:a.value}).sort((a,b)=>b.value - a.value).map(a=>a.name).join(", ");

 

   

This script could easily be rewritten to be a calculation in the result field.

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
ls_rbls
Community Expert
Community Expert
October 21, 2022

You nees to be more specific about your requirements.

 

Please describe in more detail.

Participant
October 21, 2022

I have fields A = 1, B = 2, C = 3, D = 4, E = 5. In an empty field, I want it to auto fill the rank number of field A after it compare to all the fields listed. Field with highest value number will have rank 1 and so on.

ls_rbls
Community Expert
Community Expert
October 21, 2022

If I understood correctly, fields A, B, C, D, E are already pre-filled with a value or is the user of the form able to interact and edit each field with a number value?

 

Also, are the number values that the user can enter (or select) limited to numbers between 1 through 5 only?