Skip to main content
charlesh75234165
Participant
August 9, 2019
Answered

No calculation if one field is zero

  • August 9, 2019
  • 5 replies
  • 620 views

My original equation is 20250/(Downflow+Inflow)

I want the calculated field to be blank if the inflow field stays 0.

This is the code I've been playing with, but I just can't get it to take.

event.value = (20250/(getField("DownflowCFM").value + getField("InflowCFM").value));

if(getField("InflowCFM").valueAsString === 0)) event.value = "";

Can someone help, please?

This topic has been closed for replies.
Correct answer try67

Add this as the custom validation script:

if (this.getField("InflowCFM").valueAsString == "0") event.value = "";

5 replies

charlesh75234165
Participant
August 9, 2019

I got rid of all the garbage and entered the simple equation into the Simplified field notation:

20250/((DownflowCFM)+(InflowCFM))

Can I hide the result if the inflow is 0?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 9, 2019

Add this as the custom validation script:

if (this.getField("InflowCFM").valueAsString == "0") event.value = "";

charlesh75234165
Participant
August 12, 2019

Perfect, try67. I appreciate that.

Also, Thank you to the others helping me come to the conclusion.

charlesh75234165
Participant
August 9, 2019

Ok. So there's the real issue. The calculations are working fine. I just would like it to be hidden if the inflow is 0. Sorry for the confusion.

charlesh75234165
Participant
August 9, 2019

The downflow will always have a value greater than 0, so it would never divide by zero.

The result is still there instead of blank when the inflow is 0. I want the field to be blank (or hidden) if the inflow is 0.

try67
Community Expert
Community Expert
August 9, 2019

You need to move the if-statement before the other line, and add an else at the start of that line.

Also, your condition doesn't cover the situation when the sum of both fields is zero. In that case you'll be dividing by zero, which is not an allowed operation.

Inspiring
August 9, 2019

What results are you getting with your script?

Is that result correct?

In most computer languages the "if" statement has an optional "else" statement. JavaScript is not an exception.