Skip to main content
Participant
March 4, 2024
Answered

Multiply sum of several number fields with another value when checkbox on

  • March 4, 2024
  • 1 reply
  • 668 views

I have a receipt form with many number fields. I need a field "Card Fee" to contain the product of 0.05 by the sum of four other fields when the "Charge" checkbox is ticked.  Many times only one of these summed fields ("Parts") will contain a value, which is the sum of several other fields, if that matters.

The breakdown of the equation is:

("Core Due" + "Parts"  + "Service" + "Shipping") * 0.05 = "Card Fee"

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

Use this as custom calculation script of "Card Fee" field:

var f1 = Number(this.getField("Core Due").valueAsString);
var f2 = Number(this.getField("Parts").valueAsString);
var f3 = Number(this.getField("Service").valueAsString);
var f4 = Number(this.getField("Shipping").valueAsString);
var check = this.getField("Charge").valueAsString;
var total = (f1+f2+f3+f4)*0.05;

event.value = (check === "Off") ? "" : total;

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
March 5, 2024

Use this as custom calculation script of "Card Fee" field:

var f1 = Number(this.getField("Core Due").valueAsString);
var f2 = Number(this.getField("Parts").valueAsString);
var f3 = Number(this.getField("Service").valueAsString);
var f4 = Number(this.getField("Shipping").valueAsString);
var check = this.getField("Charge").valueAsString;
var total = (f1+f2+f3+f4)*0.05;

event.value = (check === "Off") ? "" : total;
Participant
June 15, 2024

I copied and pasted and realized my Shipping field is actually named "Total Shipping." I added that to the script, but it still didn't work 😞