Adding values from Listview to a List without duplicates

Hi, I am new to Thunkable and am exploring Lists and List views, however, I am stuck and would appreciate help on the below scenario. This is what I am trying to achieve :
I have a ListView- Symptoms with the items - S1, S2, S3, S4, S5
When the user clicks on an item I want to store the item in a separate list - " Selected Symptoms"
However, before I add to this list I want to check if the item exists in the list and add ONLY if it does not exits, if it exists then it should get removed from the Selected Symptoms list.
Here is the logic I am following however this does not seem to work and I am seeing the items added multiple times and they are not getting deleted

Note: I have another listview L_Sel_Symp - to display the items from the “Selected Symptoms” list.

1 Like

Start with removing the blocks and checking back in. When you use that if “variable selectedSymptoms” is already designated as a list (which I’m assuming it is) you essentially have a list that is 1 item in a larger list (remember an array can be made of arrays) your blocks make a resulting array like this…

[ //main array
   [1,2,3], //subarray 1
   [4,5,6]  //subarray2

You have defined SelectedSymptoms as a list so you should not append the list block to it.

You don’t need this

You also don’t need the else if because you are testing the same condition.

1 Like

You all are amazing!!! I did not even think about the list within the list :slight_smile:
I removed the " List" block and adjusted the elseif to just if and it works perfectly!!! Thank you !!
here is the updated code

1 Like