If statement with && in the first argument

  • 20 March 2018
  • 8 replies
  • 9 views

Badge +7

I have a calculated value control. For its formula, I want to evaluate a couple values on the form. For the the logical_test argument (first part of If statement), I have tried the following, and  I can't quite get the syntax. Ideas?

(I am looking for payment option of "Description A" and a payment amount between 5 and 10. String1 and String2 are the options for the calculated value to display.)

If(logical_test, value_if_true, value_if_false)

If(PaymentOption == "Description A" && PaymentAmt > 4.99 && PaymentAmt < 10,"String1","String2")

If((PaymentOption == "Description A" && PaymentAmt > 4.99 && PaymentAmt < 10),"String1","String2")

If((PaymentOption == "Description A") && (PaymentAmt > 4.99) && (PaymentAmt < 10),"String1","String2")

I can get it to work with any combo of two items in the logical_test argument. It's the third one that is throwing things off. 


8 replies

Userlevel 2
Badge +11

Hi Mindy‌,

Are the used field references the Named Control names or the Item Properties? You should always name your form controls and use those and NOT the item properties. 

Also, what is the type of PaymentOption? If it's a list lookup, then you might parselookup the value: parselookup(PatmentOption)=="Description A"

Have you tried:

  1. each individual criterion?
  2. used the function equivalents of ==, < and >: equals(), lessthan(), greaterthan()?

Btw: I would always go for grouping criterias as in your 3 option: If(() && () && (), "....", "....")

Badge +7

Yes I am using the Named Control names (not Item Properties) when building the formula.

PaymentOption is a choice field.

I have tried each individual criterion to see if I just have the syntax wrong or the name of the control wrong or something like that, but each piece checks out OK.

FUNCTION EQUIVALENTS!! Let me try that. Stay tuned...

Badge +7

YES to the function equivalents!! Thank you, !!

Here is what worked for me: 

If((greaterThanOrEqual(PaymentAmt,5)) && (lessThan(PaymentAmt,10)) && (equals(PaymentOption,"yada yada.")),"yes","no") 

Badge +7

Well one more question, Jean-Pierre Huls‌ ... I actually have two of these busters to hook together. It executes the first IF but doesn't seem to do anything with the second. I can switch the two pieces around and get the same result (the first piece works but after the || doesn't). Ideas?

If((equals(PaymentOption,"yada yada"))&& (greaterThanOrEqual(PaymentAmt,5)) && (lessThan(PaymentAmt,10)),"Inc2","NO Inc2") || If((equals(PaymentOption,"blah blah")) && (greaterThanOrEqual(PaymentAmt,5)) && (lessThan(PaymentAmt,10)),"Inc2","NO Inc2")


(If((equals(PaymentOption,"yada yada"))&& (greaterThanOrEqual(PaymentAmt,5)) && (lessThan(PaymentAmt,10)),"Inc2","NO Inc2")) || (If((equals(PaymentOption,"blah blah")) && (greaterThanOrEqual(PaymentAmt,5)) && (lessThan(PaymentAmt,10)),"Inc2","NO Inc2"))

Userlevel 2
Badge +11

FYI: The initial if criteria you posted seem to work for me (NF 2013 v2.11.2.2) both with and without brackets around each criterion........

Userlevel 2
Badge +11

Hi Mindy‌, now your test reads: If(BusterCheck1 || If(BusterCheck2),"Inc2","NO Inc2")) which makes no sence. So get rid of the 2nd If (wording only) but leave tests inside its brackets: If((BusterCheck1) || (BusterCheck2),"Inc2","NO Inc2").

Badge +7

I got all turned around didn't I. Thank you, ‌ !!

Userlevel 2
Badge +11

Don't worry, this happens to the best of us cool.png.

Reply