Error "cannot compare a list with a single value"

I’m getting an error with the following code when I run the Q&A: “Error in condition: Cannot compare a list with a single value”:

  • In connection with #commercial-relationship^purpose-of-cooperation it is necessary for #recipient to familiarise {#recipient^gender = “female”: herself | = “male”: himself | = “multiple”: theirselves | else: itself} with #confidential-information of #disclosing-party (the ~#-permitted-purpose~);

The #recipient^gender datafield is a list - what am I doing wrong please?
image

As the error message indicates, you are comparing a single value to a list of values, and this does not make sense for the software — it’s like comparing a single apple to a stack of oranges.

Assuming that you indeed want to allow a single person to be both female / male / neutral at the same time, you need to use a comparison operator for lists — e.g. "female" in #recipient^gender → this essentially asks the software to check whether the single value “female” is contained in the list of assigned genders.

See the bottom of Examples of conditions – Help for more background information!

On a side note, I expect (based on your screenshot) that you are using multiple translated values.

You will probably want to read about the reason why you really don’t want to do this Using codes instead of text fragments – Help

(For example, it will require you to check on a different values in each different language. And in enabled? fields, this can really get tricky. Instead, you are advised to use a code — e.g. “F” for female, “M” for male, etc. — and then create translated labels for that code.)

Thanks Maarten, for that tip about translation and the conditions link is helpful for future reference. But I don’t see how to format that code so that if the answer is a single value (only one value for gender) then it picks the right option. EG if the answer is “female” then “herself” is used and the other options are ignored. Does that make sense?

You will then have to check whether your datafield’s value is equal to a list containining a single element — i.e. #recipient^gender = @list("female"). If the gender’s value would contain both “female” and some other element (such as “male” or “neuter”), then the expression will return false.

For future readers:

The expression

"female" in #recipient^gender

checks whether there is a value “female” in the entire list — which will not only be the case when the list contains only one element (“female”), but also when the list contains multiple elements (e.g. “female” and “male”).

1 Like