Skip to main content
Participating Frequently
September 24, 2021
Answered

Sum or product calculation, blank if zero

  • September 24, 2021
  • 1 reply
  • 2511 views

You all have been so helpful in the past, and I have another question. 

How can I do a custom calculation script of a product of two fields, or a sum of two or more fields, where when the result is 0 (zero) the field remains blank (no zero). 

 

Thanks!

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

Something like this:

var a = Number(this.getField("Field1").valueAsString);
var b = Number(this.getField("Field2").valueAsString);
if(a == 0 || b == 0)
event.value = "";
else event.value = a*b;

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 24, 2021

Something like this:

var a = Number(this.getField("Field1").valueAsString);
var b = Number(this.getField("Field2").valueAsString);
if(a == 0 || b == 0)
event.value = "";
else event.value = a*b;

try67
Community Expert
Community Expert
September 24, 2021

This works for a product, but not a sum. Why not check if the result is zero directly, instead of the values used for the calculation? So something like this:

 

var a = Number(this.getField("Field1").valueAsString);
var b = Number(this.getField("Field2").valueAsString);
event.value = a*b; // replace * with + for a sum
if (event.value==0) event.value = "";