Skip to main content
Participant
March 20, 2023
Answered

Custom Script for a "relative ranking"

  • March 20, 2023
  • 2 replies
  • 669 views

I'm trying to have the last row of my PDF display a ranking of 1st - 4th based on the scores of the fields in the row directly above this row.  I'm very new to using Adobe Acrobat Pro but was able to get automation for sum totals and averaging them in the other fields at the bottom of this document, I'm just hung up on scripting a rule to rank those fields. This is for completing Functional Behavioral Assessments in an educational setting.  Thanks for any help offered.

This topic has been closed for replies.
Correct answer CarlosCanto

Here's a ranking sample I found on SO. You would collect the 4 field values in an array and rank them using function below. You would get a ranked array back.

 

// https://stackoverflow.com/questions/14834571/ranking-array-elements

var arr = [30, 23, 21, 45];

rankings (arr); // Result: 2,3,4,1

function rankings(arr) {
    var rankingsArr = [];
    for (var i = 0; i < arr.length; i++) {
        var rank = 1;
        for (var j = 0; j < arr.length; j++) {
            if (arr[j] > arr[i]) rank++;
        }
        rankingsArr.push(rank);
    }
    return rankingsArr;
}

2 replies

Kurt Gold
Community Expert
Community Expert
March 22, 2023

As far as I can see, your question is related to Acrobat Pro, isn't it?

 

If so, you may want to ask in the Acrobat forum instead of the Illustrator forum.

 

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
March 21, 2023

Here's a ranking sample I found on SO. You would collect the 4 field values in an array and rank them using function below. You would get a ranked array back.

 

// https://stackoverflow.com/questions/14834571/ranking-array-elements

var arr = [30, 23, 21, 45];

rankings (arr); // Result: 2,3,4,1

function rankings(arr) {
    var rankingsArr = [];
    for (var i = 0; i < arr.length; i++) {
        var rank = 1;
        for (var j = 0; j < arr.length; j++) {
            if (arr[j] > arr[i]) rank++;
        }
        rankingsArr.push(rank);
    }
    return rankingsArr;
}
Participant
March 22, 2023

I wish that made it make more sense... I'm guessing I can't just copy and paste this into the Custom calculation script box in the field properties and it'll magically work...

CarlosCanto
Community Expert
Community Expert
March 23, 2023

Can you provide a sample file for testing? I don't know Acrobat Javascript from memory as much as I do Illustrator.