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

Custom Script for a "relative ranking"

New Here ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

331

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

Community Expert , Mar 20, 2023 Mar 20, 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++
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

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;
}

Votes

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
New Here ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

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...

Votes

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 Expert ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

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

Votes

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 Expert ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

LATEST

but to answer your question, no it would not magically work if you copy and paste it.

 

this line represents the 4 field values you'll have to collect first

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

 

Votes

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 Expert ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

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.

 

Votes

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