Issue With Logical Operators & Nested If Statement


Badge +3

Hi folks,

    I'm having issues with my nested if statements. My conditional statement is shown in the image. I want my form to act this way;

  •    If any of the statements in the bracket following the "or" opeartor is true, then display message1
  •    If all the statements in the brackets following the "and" operator are true, display message 2.
  • else, display message 3

I think I may be applying the "or" statement incorrectly. This worked fine in my excel form. is it different with nintex?


11 replies

Userlevel 6
Badge +15

Hmm, seems right to me.

198735_pastedImage_1.png

What current displays if you meet any of your OR conditions?

What displays if you meet NONE of your OR conditions but SOME of your AND conditions?

What's displaying if you don't meet ANY conditions?

Knowing what happens at present will help for sure! ...Probably!

Badge +3

Message 1 is being displayed when either of  the first 2 statements in the "or" bracket is true. It's ignoring the remaining statements. 

I m getting the desired outcome for both message 2 and 3.

Userlevel 5
Badge +12

Sometimes its better to break a big problem into smaller parts and test.   In other words, test each rule part, piece by piece to make sure you are getting a "true" result and then keeping building your rule up from there.   May take more dev time with this approach, but a lot less on the troubleshooting side.

Userlevel 6
Badge +15

Are these variables attached to checkboxes or dropdowns or what?

Badge +3

They are attached to check boxes.

Badge +10

Try using || and &&

If( ExtNoForDialExtensions1 == "No" || RestrictSetss =="Yes" || PickUp=="Yes" || AboveOne =="Yes" || Multical== "Yes" || DigitalTrans == "Yes", "Message 1" ,If( ExtNoForDialExtensions1 == "No" && RestrictSetss =="No" && PickUp=="No" && AboveOne =="No" && Multical== "No" && DigitalTrans == "No","Message 2") ,"Messge 3")

User the proper controls names in the above lines.

Badge +3

Thanks you all for your contributions!

I found that the issue with my nested if statement was that of hierarchy. I arranged the variables in the "or" logical operators in the order they appear in my form and it worked. 

Assuming the variables are A,B,C,D and E defined in ascending order in the form. Then my if Statements should be: 

If( A == "No" || B=="Yes" || C=="Yes" || D =="Yes" || E== "Yes" || F == "Yes", "Message 1" ,If( A == "No" && B =="No" && C=="No" && D=="No" && E= "No" && F == "No","Message 2") ,"Messge 3")

I also did some testing and the order of the variables doesn't affect the "AND" operator.

Thought I should share this for anyone who may have the same challenge I did.

Cheers!

Userlevel 5
Badge +14

,

1. problem with your original formula was that you supplied too many arguments to or() and and() functions.

see their definition in help pages - they both can ONLY accept two arguments

198787_pastedImage_10.png

http://help.nintex.com/en-US/nintex2013/help/#Forms/RootCategory/Designer/Nintex.Forms.RuntimeFunctions.htm%3FTocPath%3D… 

so whatever you supplied as extra argument(s) was simply ignored.

2. have you really used a formula from your most recent post?

unlike your original post, this one is syntactically not correct, so can not (reliably) work.

3.

I arranged the variables in the "or" logical operators in the order they appear in my form and it worked. 

why do you think order/placement of controls on the form should/might have impact on formula evaluation?

would you expect that with every single control movement or when a control is added deleted, one would need to rewrite all the rules/calculation/etc just because of that?

since you turned to use javascript operators, it's all about the way of how javascript logical expression is evaluated, precedence of operators, what value are considered/convertable to true, etc.

if you can not spot the problem in evaluation, it's always the best approach to proceed from evaluation of simplest possible expression up to complex one(s), as Mike M‌ suggested above

Badge +3

1. I read the documentation before I even posted my question. No where in the document did it explicitly say that the "or" logical operator can only receive two arguments( aka I took the usage as an example). 

If( or (A == "No" , B=="Yes" , C=="Yes" , D =="Yes", E== "Yes" , F == "Yes"), "Message 1" ,If( and(A == "No",   B =="No", C=="No" , D=="No" , E= "No" , F == "No"),"Message 2" ,"Messge 3"))

works too. Only after arranging the variable in the order they appear in the form

2.  Yes, and it works! I used Sojan Mathew suggestion because Nintex won't accept the formula in my initial post. both formulas are syntactically correct.

3. I don't know why this is so in Nintex. I just shared my experience.

Cheers

Userlevel 5
Badge +12

JS syntax is cleaner than nested rules, but you could run into some issues in the mobile world.   If mobile isn't a consideration then JS syntax all the way.  See   for more details (Figured I would point this out just as an FYI to those who might browse this  post).

Userlevel 5
Badge +14

can you post details on env you test on?

1. could you post a link to doc which you refer to and which allows more then 2 arguments to or()/and() functions?

I'm just curios, since I've seen several times constructs like yours but have never known where does it come from.

if I test on NF2013 on-prem 2.7.0.0&2.9.4.0, following expression evaluated in both cases to (expected) false

198839_pastedImage_1.png

from what you have written, it should evaluate to true.

would you mind to test the same on your env?

2.now the formula looks syntactically better happy.png. you have mistyped one bracket in previous post.

3. would you mind to post an example what exactly do you experience?

4. you have said above, your formula references/variables are checboxes, so are they Yes/No controls/list fieds?

Reply