Copy link to clipboard
Copied
How do I write a custom calculation for:
Text1 + Text2 + Text3 = Text20
If sum is 0 then value is 0
If sum is any number between 1 - 300 then value is 300
If sum is >300 then value is sum
Here is what is NOT working:
if( Text20 <= 300 ) {
event.value = 300; // value is 300 when sum is less than or equal to 300;
} else {
if ( Text20 == 0 ) {
event.value == 0; // value is 0 when sum is equal to 0;
} else {
event.value = Text20; // else value is the sum;
}
}
1 Correct answer
Use this code as the custom calculation script of your field:
var total = Number(this.getField("Text1").valueAsString) + Number(this.getField("Text2").valueAsString) + Number(this.getField("Text3").valueAsString);
if (total>1 && total<300) total = 300;
event.value = total;
Copy link to clipboard
Copied
Looks about right, except you are missing the compulsory "getField" call.
Copy link to clipboard
Copied
Use this code as the custom calculation script of your field:
var total = Number(this.getField("Text1").valueAsString) + Number(this.getField("Text2").valueAsString) + Number(this.getField("Text3").valueAsString);
if (total>1 && total<300) total = 300;
event.value = total;

