Copy link to clipboard
Copied
Hi
I have a custom Java code to caluclate times between Take Off & landing. Format in HH:MM, format out should be HH:MM. However, the result is displaying NaN:NaN which is annoying until you enter times. Here is my code: Seems to work, just the NaN is annoying whilst the cells are blank.
var hrsStart = parseInt(this.getField("Take Off Z1").value.split(":")[0]);
var minStart = parseInt(this.getField("Take Off Z1").value.split(":")[1]);
var hrsEnd = parseInt(this.getField("Landing Z1").value.split(":")[0]);
var minEnd = parseInt(this.getField("Landing Z1").value.split(":")[1]);
if (minStart > minEnd) {
var minRez = 60 + minEnd - minStart;
var hrsRez = hrsEnd - 1 - hrsStart;
} else {
var minRez = minEnd - minStart;
var hrsRez = hrsEnd - hrsStart;
}
this.getField("Flight Time1").value = hrsRez + ":" + minRez;
Add condition to check if fields are empty:
if(this.getField("Take Off Z1").valueAsString == "" || this.getField("Landing Z1").valueAsString == "")
this.getField("Flight Time1").value = "";
else
this.getField("Flight Time1").value = hrsRez + ":" + minRez;
TIP: if you use code in "Flight Time1" field, instead of: this.getField("Flight Time1").value you can use: event.value
Copy link to clipboard
Copied
Perform the calculation only when the cells are not empty.
Copy link to clipboard
Copied
And how to initiate that?
Copy link to clipboard
Copied
Add condition to check if fields are empty:
if(this.getField("Take Off Z1").valueAsString == "" || this.getField("Landing Z1").valueAsString == "")
this.getField("Flight Time1").value = "";
else
this.getField("Flight Time1").value = hrsRez + ":" + minRez;
TIP: if you use code in "Flight Time1" field, instead of: this.getField("Flight Time1").value you can use: event.value
Copy link to clipboard
Copied
Hi Nesa.
Oohh thank you very much! worked perfect! Many thanks