Customer calculation: Perform action X if fields contain info, perform Y if fields are blank or null
Hi all,
Disclaimer upfront, I am a novice at JavaScript. I've tried reusing some that has worked for me in past scenarios, and i've searched the internet extensively and just cannot get an answer. Would appreciate some help!
In concept, this seems like such a simple problem, so I'm frustrated I can't get it working. I have a table with a lot of form fields. Each row is a line item. Some rows only have a member price and some rows have a member and non-member price. Then there is a quantity field for the user to enter data. And a total field. The total field is working beautifully when there is only one price. I have the calculation set to do a product of the price * quantity. The problem I am having is when there are 2 prices. I need to be able to tell it which price to use. So, I was trying to add a Custom Calculation script.
- If the member number text field has a value OR one of the 3 membership types is > 0, it should use the member price.
- Else if the Member Number text field is blank or null AND the 3 membership types are 0, then it should use the non-member price * quantity = total.
- I also am not sure if I need to tell it not to do anything if the quantity field for the row the calculation is on is blank.
Right now it calculates both formulas when i run them independantly. But even though in the form I only have a value in the quantity field of the row i'm trying to calculate, all the other fields i specified are blank, it seems like it will not move to the else if scenario.
//Define vars
var MemNum = this.getField("MemberNumber").value;
var AnnualMem = this.getField("AnnualMembershipTotal").value;
var ThreeYr = this.getField("ThreeYearMembershipTotal").value;
var AssociateMem = this.getField("AssociateMemberTotal").value;
var Total = this.getField("AmateurCardTotal").value;
var Qty = this.getField("AmateurCardQuantity").value;
var Member = this.getField("AmateurCardPriceMember").value;
var NonMember = this.getField("AmateurCardPriceNonMember").value;
if ((MemNum !== "") || (!MemNum) || (AnnualMem > 0) || (ThreeYr > 0) || (AssociateMem > 0)) { Total = Member * Qty; }
else if ((MemNum == "") || (MemNum) || (AnnualMem = 0) || (ThreeYr = 0) || (AssociateMem = 0)) { Total = NonMember * Qty;}
