Skip to main content
Participating Frequently
May 30, 2022
Answered

Help me with calculating minimum of which some fields will be blank

  • May 30, 2022
  • 1 reply
  • 2429 views

I will let you know before posting this I did try to search for help to no avail.

I have uploade a form that I am using.

I have 18 feilds that I want to find the minimum value for, some of the feilds will remain blank so I cannot have it counted as a minimum value because it will thought of as a zero.

18 Field Names: PL1, PL2, PL3, PL4, PL5, PL6, PL7, PL8, FLS, LCS, RCS, FRS, SL1, SL2, SL3, SL4, SL5 and SL6.

The calculated feild; MCV

MCV stands for Minimum Vetical Clearance

 

I do not know anything about Jave Script but am trying to learn.

This topic has been closed for replies.
Correct answer try67

Yes it weird, and I have never understood this, but if the structure does not have luminaires or a walkway the minimum clearance can only be 19.0 feet. If there are luminaires and/or a walkway the minimum can only be 17.5' to pass underneith. So if the structure has luminaires and/or a walkway then the "CB17_5" has the oportunity to be be checked if the clearence is below 17.5'. If there are no luminaires or walkways then the minumum clearanc can only be 19.0'.

in other worrd if there are no luminaires or walkway then the "CB19_0" will be the only check box that will become checked even if the MVC goes below 17.5'. If either of the other two checkboxes are checked the the CB17_0 comes into play. Whew! I sure hope this makes sense!


IF I understood you correctly, this should work:

 

if (this.getField("Lum_Present").valueAsString!="Off" || this.getField("WW_Present").valueAsString!="Off") {
	if (minValue<17.5) {
		this.getField("CB17_5").checkThisBox(0, true);
	}
} else if (minValue<19) {
	this.getField("CB19_0").checkThisBox(0, true);
}

1 reply

try67
Community Expert
Community Expert
May 30, 2022

You can use this code to achieve it, as the custom calculation script of MVC:

 

var fields = ["PL1", "PL2", "PL3", "PL4", "PL5", "PL6", "PL7", "PL8", "FLS", "LCS", "RCS", "FRS", "SL1", "SL2", "SL3", "SL4", "SL5", "SL6"];
var minValue = Infinity;
for (var i in fields) {
	var f = this.getField(fields[i]);
	if (f==null) {console.println("Error! Can't find: " + fields[i]); continue;}
	var v = f.valueAsString;
	if (v!="") minValue = Math.min(minValue, Number(v));
}
if (minValue==Infinity) event.value = "";
else event.value = minValue;

 

However, there are errors in some other calc scripts in your file that must be fixed for it to work correctly.

Participating Frequently
May 30, 2022

Try67, Thanks so much for your help. You are amazing. Thanks for the quick reply.