Server Action condition, "or" "||" doesn't work?

Hi,

I have a CONDITION in one of my Server Actions. It simply states that if a field is NOT either/or then carry out the action. Am I doing something wrong. I find whenever I use OR. “|” it never works (condition is not honoured)
If I just use I exclude it works fine.

qr_name!='exclude_item_1'||qr_name!='exclude_item_2'

I also tried this:

qr_name!='exclude_item_1'||'exclude_item_2'

But this works if I use one exclude:

`qr_name!=‘exclude_item_1’

Not completely clear what exactly are you trying to check here. Can you explain what is the exact thing you are trying to check with the condition?

In the CONDITION I am checking if the field name IS NOT from one of the queries I have in the Server Actions - so I want the condition to check if field name is NOT “exclude_item_1” OR “exclude_item_2”

For example. the query would list a bunch of names, and I want the condition to check if a field is NOT “Adam” or “John”.

The single query returns a single record, so you want to check if a value of a column returned by this exact single record is equal to John or Adam? If it is not - run the send mail?
Or do you want to loop through all the records and send email to all except John and Adam?

Yes, the first part is correct -

The single query returns a single record, so you want to check if a value of a column returned by this exact single record is equal to John or Adam? If it is not - run the send mail?

I see in your screenshot there’s an empty space after 'John ' in your expression, is that by intention?
And what is actually not working in this case?
If the name is John or Adam, does it return true, or?

Is not "Adam" AND Is not "John" perhaps?

qr_name.xyz.name != 'John' && qr_name.xyz.name != 'Adam'

Alternative way:

!(qr_name.xyz.name == 'John') && !(qr_name.xyz.name == 'Adam')
2 Likes

Regarding the space, that was a typo. I fixed that (still the same issue)
What’s happens is that even if the value is “John” or “Adam” it still sends the email and it shouldn’t.

Check @Apple’s reply :slight_smile: You want to check if the name is not Adam AND John, not OR.

1 Like

Thank @Teodor @Apple was correct. :slight_smile:

Thanks @Apple. You are correct. It worked when I changed it to &&. Thanks for there alternative way as well. :slight_smile:

2 Likes

If you have many names to check, the expression could become rather long and unwieldy.

Yet another alternative would be to put the list of names in a variable and use ‘contains’, so the condition would be something like:
v_list.contains($_GET.name.lowercase())
… where v_list contains the list (which could of course be the result of a query) and the GET variable is the name to check. Bear in mind ‘contains’ is case-sensitive, so you will probably want to make both the contents of the list and the parameter lowercase.

1 Like

that’s a good idea too @TomD. Thank you! I was just thinking about how I would setup the condition if I have many exclusions. I will give this a try. Do you have a screenshot showing what you’ve explained? Much appreciated.

Something like:

image

You will need to deal with no GET parameter being sent.

PS You might need to tweak this if you want more precise matching. Eg as it stands 'mart' sent as a parameter will match 'martin'. To prevent this, you could check also for word separators. Eg separate the words in the list with a '|' character (and add it also at the beginning and end of the list) and then add the character either side of the GET parameter.

1 Like

Awesome! Thanks very much @TomD! Much appreciated.

1 Like