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

Capping Sum of Fields in a Form

New Here ,
Sep 17, 2024 Sep 17, 2024

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?

TOPICS
Create PDFs , JavaScript , PDF
517
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 17, 2024 Sep 17, 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;

View solution in original post

Translate
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 ,
Sep 17, 2024 Sep 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.

Translate
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 ,
Sep 17, 2024 Sep 17, 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;

Translate
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 ,
Sep 18, 2024 Sep 18, 2024
LATEST

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

Translate
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