Copy link to clipboard
Copied
Hi All,
I have the following script in a field that pulls berth depths from another field
var allberths = {
"SCPT": "10.1",
"WBCT": "10.9",
"WHT4": "11.1",
"GLB1": "12.0",
"GLB2": "12.0",
"GLB7": "10.6",
"GLB8": "9.4",
"GOR1": "13.2",
"GOR2": "8.9",
"WAHEN": "4.6",
"ICCD": "11.0",
"FLTBASE": "8.0",
"CBOFF": "11.8",
"BANK1": "14.0",
"BANK2": "13.5",
"ATHOL BAY": "11.6",
};
var movementField = this.getField("MOVEMENT");
var fromField = this.getField("FROM");
var toField = this.getField("TO");
if (movementField.value === "SELECT ONE") {
event.value = "0.00";
} else if (movementField.value === "ARRIVAL" && fromField.value === "SEA" && toField.value === "SELECT ONE") {
event.value = "0.00";
} else if (movementField.value === "DEPARTURE" && fromField.value === "SELECT ONE" && toField.value === "SEA") {
event.value = "0.00";
} else if (movementField.value === "ARRIVAL" && allberths[toField.value]) { event.value = allberths[toField.value];
} else if (movementField.value === "DEPARTURE" && allberths[fromField.value]) { event.value = allberths[fromField.value];
} else if (movementField.value === "REMOVAL" && allberths[toField.value]) { event.value = allberths[toField.value];
} else { event.value = "0.00";
}
I was going to put in an option called "other" in my table, but want to able to enter the depth value manually but not sure how to do it. Currently if I enter a value manually it just reverts back to the value from the table.
Thanks
LC
Copy link to clipboard
Copied
Remove last line:
else { event.value = "0.00";
}
Copy link to clipboard
Copied
Thanks for that
see my comments below - i think i now have it working the way I want.
Copy link to clipboard
Copied
Use this code in the "else if" where the "Other" value is specified.
else if(movementField.value == "Other");
event.rc = false;
Setting "event.rc" to false blocks the script from having any effect on the field value.
It's also a best coding practice to provide complete conditions. So use a final "else" that sets the value to indicate an invalid selection.
And, just a suggestion. It is not necessary or a good idea to use the identity operator (===) for text comparisons. Use the equality operator (==) .
Copy link to clipboard
Copied
Thanks for the advice Thom, much appreciated.
I will make the above changes as youve suggested.
cheers
LC
Copy link to clipboard
Copied
After a bit reading and playing etc I settled for the following
if (movementField.value == "SELECT ONE") {
event.value = "0.00";
} else if (movementField.value == "ARRIVAL" && fromField.value == "SEA" && toField.value == "SELECT ONE") {
event.value = "0.00";
} else if (movementField.value == "DEPARTURE" && fromField.value == "SELECT ONE" && toField.value == "SEA") {
event.value = "0.00";
} else if (fromField.value == "OTHER" || toField.value == "OTHER") {
event.rc = true;
} else if (movementField.value == "ARRIVAL" && allberths[toField.value]) {
event.value = allberths[toField.value];
} else if (movementField.value == "DEPARTURE" && allberths[fromField.value]) {
event.value = allberths[fromField.value];
} else if (movementField.value == "REMOVAL" && allberths[toField.value]) {
event.value = allberths[toField.value];
} else { event.value = "0.00";
}
this seems to be allowing the user to manually enter their own value when "Other" is selected.
Copy link to clipboard
Copied
Actually, event.rc should be set to false.
You're code works, not because the calculation is being blocked, but because no value is being returned to event.value, which works out to about the same thing.
Copy link to clipboard
Copied
Thanks. I will change it over.
cheers
LC
Copy link to clipboard
Copied
In order to override a calculation there as to be a way for the script to know not to set the value. And the opposite has to be true as well. The script needs to know that it needs to set the value.
The simplest solution is use an indicator value. You mentioned using an "Ohter" value in something? Is this a form field? If so then selecting "Other" could be used to block the calculation so a manual value could be entered.
Copy link to clipboard
Copied
Thanks,
Yep "Other" will be an option to select instead of the ones listed above. I have added "other": "", as the last line in my table above
and removed the
else { event.value = "0.00";
as per Nesa's suggestion above. I think it now works as required, just need to do some more testing to be sure.
Thanks for your help.