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

If/ then calculated function

New Here ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

I am trying to set a calculated field where I want the equation to say " If the sum of the selected fields is greater than $500, then display $500, if not display sum of selected fields". I am not experience is JavaScipt and need assistance writing the script.

TOPICS
Create PDFs

Views

103

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 ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

LATEST

You can do it using this code as the custom calculation script of the total field:

 

var fieldsToAdd = ["Amount1", "Amount2", "Amount3"]; // replace with actual field names
var total = 0;
for (var i in fieldsToAdd) {
	var v = Number(this.getField(fieldsToAdd[i]).valueAsString);
	total+=v;
}
event.value = Math.min(500, v);

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