Multiple If statements for multiple conditions including a checkbox
Copy link to clipboard
Copied
Hello, I’m looking for help in coming up with the correct formula/syntax for a field on a payment application form. I’ve tried many, many variations and can get the LessRetainage field working for just two conditions (that are math-based on $amounts entered in other fields), but when I throw in a third condition (user has to select checkbox to let my office know if the submitted pay app is a final pay app) it goes off the rails.
FinalPayApp is the check box. A zero cannot show in the LessRetainage field when someone first opens the pdf in case they choose to print it and handwrite the info. The conditions for the autopopulation of the LessRetainage field are: If Total Work Completed to Date & Materials Presently Stored (#3) is less than or equal to 50% of Total Contract to Date (C), Retainage = #3 x 0.05. Once #3 exceeds 50% of C and up until project is complete, Retainage = C x 0.025. $0 is retained on final payment application.
Only the contractor can indicate when a pay app is the final pay app; it is not entirely math based, there are construction site and other paperwork conditions that must be met. At a minimum for a final pay app, #3 must equal C, so if a contractor mistakenly selects the FinalPayApp checkbox when #3 doesn't equal C, an error message needs to show in the LessRetainage field.
My formula the LessRetainage field so far that doesn’t work is:
var C = this.getField("TotalContractToDate").value;
var TWSM = this.getField("TotalCompletedWorkStoredMaterials").value;
var v1 = this.getField("FinalPayApp").value;
if (TWSM.value <=(.5 * C.value)) {event.value = .05 * TWSM.value;}
else if ((TWSM.value <=(.5 * C.value)) && (v1 == "")) {event.value = .05 * TWSM.value;}
else if ((TWSM.value <=(.5 * C.value)) && (v1 == "Yes")) {event.value = //Error: final pay. app. must be 100% work completed.//;}
else if (TWSM.value >(.5 * C.value)) {event.value = .025 * C.value;}
else if ((TWSM.value >(.5 * C.value)) && (v1 == "")) {event.value = .025 * C.value;}
else if ((TWSM.value = C.value) && (v1 == "Yes")) {event.value = 0;}
else {event.value = "";}
Any help would be appreciated!
Copy link to clipboard
Copied
You're not accessing the values correctly.
You've defined the variables to be the value of the fields in the first three lines, which is fine, but then later on you're referring to the value properties of those variables, which don't exist.
Remove the ".value" from all instances where you access those three variables after the first three lines.

