OR statement not evaluating like i would expect?

I need to hide a button if a returned data field isn’t one of two options. If the returned usertype is NOT admin, nor is it sysadmin… the button should be hidden.

I have tried every combination of || to make this work as expected. However I can only get it to evaluate the first condition of the or statement. If the second part of the OR is true… it doesn’t matter. What am I missing??

None of the following have worked when the usertype is sysadmin. It ONLY works for admin.

((userDetails.data.query.usertype !== admin) || (userDetails.data.query.usertype !== sysadmin))
((userDetails.data.query.usertype != admin) || (userDetails.data.query.usertype != sysadmin))
userDetails.data.query.usertype!=('admin' || 'sysadmin')
(userDetails.data.query.usertype != ('admin' || 'sysadmin'))

Have you tried an AND?

((userDetails.data.query.usertype != admin) && (userDetails.data.query.usertype != sysadmin))

They both can’t be true. You only get one usertype per user that’s logged in. So if the user is admin OR sysadmin, the button should Show. So AND would never equate to true.

I prefer to be more prescriptive in situations like this. Have you considered changing the behavior from “hide” to “show” and then checking for the profiles you want to expose the button to?

The AND is just saying it’s not either of the values. Could you try it and see what the outcome is?

fairly certain AND means both have to equate to true for the statement to be true. Results below using &&

Shows for no one… because both aren’t true.
((userDetails.data.query.usertype != admin) && (userDetails.data.query.usertype != sysadmin))

sure, but if the issue is with how wappler uses ||, it would be the same problem i’m having now. I don’t think the issue is with the hide.

When it was one condition, just “admin”, it works fine. It works fine for whatever is listed first in the OR. So it’s either javascript disjunction issue or wappler issue.

Are you using a SHOW or a HIDE? Please screenshot the full code.

If you want to hide a button when the usertype is neither admin nor sysadmin then your expression needs to be:

dmx-hide="(userDetails.data.query.usertype != 'admin') && (userDetails.data.query.usertype != 'sysadmin')"

I’m adding Teodor to my christmas card list…

I was overthinking it. Thank you teodor!

1 Like

you were correct. I appreciate you too, but no christmas card list yet lol.

1 Like

Why no Christmas card for @kfawcett?
Didn’t he get the answer first? :thinking:
Sorry to hear you’ve been missed off the list Keith! 🤷

2 Likes