Skip to main content
Participant
September 17, 2024
Answered

Capping Sum of Fields in a Form

  • September 17, 2024
  • 1 reply
  • 485 views

I have a form that has 27 different fields that have $$ amounts in them.     I need to add them all up to create a sum,  but if the sum exceeds $5000, I need it to only show $5000 - no higher.    I've tried many different forums and suggestions online, but can't seem to knock this one out.  This is literally the last field I need for this document.  Can anyone assist?

This topic has been closed for replies.
Correct answer Nesa Nurani

There is an easier way to achieve this, use built in 'sum' option in the total field, under 'calculate' tab select 'Value is the' leave as sum(+) and pick your fields, in 'Validate' tab enter this script:
if(Number(event.value) > 5000)event.value = 5000;

1 reply

PDF Automation Station
Community Expert
Community Expert
September 17, 2024

Create a custom calculation script like this:

var total=

Number(this.getField("Field1").valueAsString)+

Number(this.getField("Field2").valueAsString)+

Number(this.getField("Field3").valueAsString)+

Number(this.getField("Field4").valueAsString)...etc.

if(total > 5000)

{event.value=5000}

else

{event.value=total}

 

If you're fields have a specific consistent naming convention with numbers, you might be able to avoid typing out every field name into the script.

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 18, 2024

There is an easier way to achieve this, use built in 'sum' option in the total field, under 'calculate' tab select 'Value is the' leave as sum(+) and pick your fields, in 'Validate' tab enter this script:
if(Number(event.value) > 5000)event.value = 5000;

Participant
September 18, 2024

This worked beautifully!  I knew there was a simple answer to this!  I apprecaite your help!