Adobe Form Custom Calculation Script | Community
Skip to main content
Level 1
January 27, 2026
Question

Adobe Form Custom Calculation Script

  • January 27, 2026
  • 2 replies
  • 15 views

Having an issue with script for a custom calculation.

I need to take number from a field and search through 323 fields to find a matching number, then search through 323 percentage fields and pull the matching field number percent value.

This code worked on a small sample that I input, but is not working with my actual program:

var target = this.getField("TargetNumberField").value; // The number you are searching for
var found = false;
var result = 0;

// Loop through 323 fields (assuming named Lookup1, Lookup2... or similar)
for (var i = 1; i <= 323; i++) {
if (this.getField("Lookup" + i).value == target) {
// Match found, get corresponding percentage field
result = this.getField("Percent" + i).value;
found = true;
break; // Stop loop
}
}

Any and all help is greatly appreciated!

if (found) {
event.value = result;
} else {
event.value = ""; // Or 0 if no match
}

 

 

    2 replies

    ninoskuflic
    Level 2
    January 28, 2026

    Hey ​@Bev_Deaton, I think this post might be in the wrong community. This community is for the Adobe Workfront product and JavaScript is not supported within this tool. 😀

    If this solved your issue, please mark it as solved so others can find the solution faster.
    Adobe Employee
    February 5, 2026

    Hi ​@Bev_Deaton,

    Thanks for reaching out and for your patience while we reviewed the custom calculation script.

    I believe I have identified the issue. It seems that the problem is not with the loop logic itself but with how Acrobat(assuming you are testing this with a PDF) handles field values in larger, real-world forms. In the full file, some fields return values as formatted text (for example, numbers with commas or stored as strings), which prevents a direct match during the comparison. Additionally, if any lookup or percentage field name does not exist exactly as expected, the script can stop processing.

    I have tried to update the script to normalise field values before comparing them. I am not sure if this will work; however, I request that you to please apply these changes and check if the calculation works as expected across all 323 fields.

    // Get and normalize the target
    var tField = this.getField("TargetNumberField");
    var target = tField ? ("" + tField.value).replace(/[, ]+/g, "").trim() : "";

    var found = false;
    var result = "";

    // Only search if target is not blank
    if (target !== "") {
        for (var i = 1; i <= 323; i++) {

            var lField = this.getField("Lookup" + i);
            if (!lField) continue; // field name doesn't exist, skip

            var lookupVal = ("" + lField.value).replace(/[, ]+/g, "").trim();
            if (lookupVal === target) {
                var pField = this.getField("Percent" + i);
                result = pField ? pField.value : "";
                found = true;
                break;
            }
        }
    }

    event.value = found ? result : "";


    Thanks
    Pranay