Proper syntax for logic functions adding conditional items to an array

I’m trying to create a ClickUp task CRM record with a label-type custom field storing a label for each conversion action a client has completed. I’m pulling in appointment data, and want to label the client in ClickUp with “free consult booked” if they have a free appointment type, and also with “paid appointment booked” if they have a paid appointment type. The value passed to the label-type custom field must be an array of one or more labels.

Currently I’ve got this function to create an empty array and add conditional label values to it:


First it checks if the incoming appointment type is any of these free types:
image
If so, the if() function should return the label for “free consult booked”:
image
If it’s not a free type, another if() function checks if it’s any of the paid types, and returns that label.
However, I’m getting an error message:
image
Failed to map ‘3.value’: Function ‘add’ finished with error! Function ‘if’ finished with error! Cannot read properties of undefined (reading ‘type’)
I’m unfamiliar with this error type and am unclear what that last part means: “Cannot read properties of undefined (reading ‘type’).” Guessing it’s the wrong data type, like maybe it’s somehow not returning an array.
Also I tried adding an {{emptyString}} to the last if() function because it was missing a value2 “else” argument:
image
That had no effect.
I suspect I may be doing something wrong with the add(emptyArray) bit.
I made a simplified test version to try to locate which part of the function is breaking. This worked fine, outputting 1 when I input 1, 2 when I input 2, and “else” when I input anything else, as it should:


There’s no OR syntax here, so I added some to see if that was the problem:


I started getting some weird behavior. It seems the set variable input was ignoring whatever was coming from the compose string module, and just returning “odd” every time, as if somehow the variable was now persisting across runs, though it hadn’t before:
I went back and realized that issue started before I added the OR though, on the third run when I input “3” to the compose string module. The set variable output “else” as expected, but somehow the input was also “else,” not “3,” where the previous runs had inputs of 1 and 2, which was what I’d put into the compose string. Is there some behavior where string variable values like “else” persist across runs, while number values like 1 and 2 don’t?


So this is now a whole different issue. I’m going to put in a ticket on it, but can anyone help with the initial issue?
Any other ideas much appreciated!

Hi :wave:t5:,

I believe your function did not work properly because the “if” function needs the whole expression in case you work with the “OR” operator.
→ The “OR” logic operator performs disjunction on two expressions, not results/values.

Your simplified formula could then look as per the below picture.

2 Likes