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

17

Likes

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
Adobe Community Professional ,
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);

Likes

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