Skip to main content
Participating Frequently
May 30, 2022
해결됨

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

  • May 30, 2022
  • 1 답변
  • 2429 조회

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.

이 주제는 답변이 닫혔습니다.
최고의 답변: 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 답변

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
quote

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.

 By @try67

 

What are the other errors did you see? I dont recall any other calcs on this sheet, please advise!

try67
Community Expert
Community Expert
May 30, 2022

Every calculation script under the SLx fields, basically. You've written code but placed it in the Simplified Field Notation section, instead of the Custom Calculation Script section.


Also, PL1 and MVC (the previous code, that is).